Pseudo-hacky sugar around generators. If you write nested for loops or nested functions a(b(c([1,2,3]))) this might help you.
Basically it looks like this:
[1, 2, 3] | add(2) | list == [3, 4, 5]
where
@worker
def add(items, n):
for i in items:
yield i + n
The leftmost argument always is the iterator coming from the left side. The other arguments represent a bound state. Using this worker is a two-step process.
adder = add(2) # bind a state in a closure adder([1, 2, 3]) == [3, 4, 5] # apply an iterator
workers tend to be very simple and short, reusable and easy to test.
@worker
def echo(items):
for i in items: yield i
echo = echo() # echo 'has' no state
assert [1, 2, 3] | echo == [1, 2, 3]
Sometimes you can achieve something like this:
filter_audio_files = fs.filter_by_ext(['.mp3'])
@producer
def folders_with_audio_files(path):
for root, folders, filenames in os.walk(path):
if any(filenames | filter_audio_files):
yield root
@worker
def that_need_fix(paths):
for path in paths:
files = listdir(path) | filter_audio_files | join_path(path) | list
dos_names = files | get_83DOS_name | list
if files.sort() != dos_names.sort():
yield path
that_need_fix = that_need_fix()
# and the outermost commands in a script then look like this
#give me all folders with mp3-files inside, e.g. print them to stdout
folders_with_audio_files(root)
#give me all folder that need a specific fix, aka dry-mode
folders_with_audio_files(root) | that_need_fix
#actually apply a fix to these folders
folders_with_audio_files(root) | that_need_fix | apply_fix
Metadata
Release files for useless.pipes 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| useless.pipes-0.0.1.zip | 8.7 kB | Without provenance | Details for useless.pipes-0.0.1.zip |
Release files / useless.pipes-0.0.1.zip
| Download URL | useless.pipes-0.0.1.zip |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
752f9334f36b4e11ecb6ba79afd5f595d2496246beb3b24e0b1ddfd91997a57e
|
|
BLAKE2b-256 checksum How to use checksums |
a04856a0f8a6f4158fb93f094792fde791f13c3bd3d99642a9647fadc5b6bb73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for useless.pipes 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.