morepipes
Based on the pipe library, adding more utilities and pipes to it
Some pipes are inspired by other programming languages (eg Rust)
Installation
pip install morepipes
Examples
Consume iterable
range(9) | where(lambda x: x % 2) | collect
# List of odd numbers
Cut iterables
range(9) | take(5) | drop(2) | collect
# [2, 3, 4]
Remove duplicates
a = [1, 3, 3, 1, 2, 4, 4, 2, 2, 2, 1, 4, 4, 3, 3, 1]
b = a | squeeze | collect
# [1, 3, 1, 2, 4, 2, 1, 4, 3, 1], remove consecutive duplicates
c = b | unique | collect
# [1, 3, 2, 4]
Manipulate iterations
range(9) | chunks(4)
# [[0, 1, 2, 3], [4, 5, 6, 7]]
range(9) | alternate
# [0, 2, 4, 6, 8]
Side effects
range(9) | ... | inspect | ...
# Prints out each object received on evaluation
Or, more generally
range(9) | ... | foreach(print) | ...
There's also bindings for builtins and itertools
[1, 2, 3] | combinations(2)
[1, 2, 3] | permutations
[1, 2, 3] | cycle
[1, 2, 3] | imap(iseven)
[1, 2, 3] | isum # 6, equivalent to sum([1, 2, 3])
[1, 2, 3] | iall(iseven) # equivalent to all(iseven(x) for x in [1, 2, 3])
[1, 2, 3] | iany(iseven) # equivalent to any(iseven(x) for x in [1, 2, 3])
[1, 2, 3] | ilen # 3, equivalent to len([1, 2, 3])
isum, iall, iany, ilen is useful when working with long pipe chains (no messy parentheses)
New: Partial Pipes
Creating a partial pipe
reverse_sort = P | reverse | sort
# P is a special object placeholder
Using a partial pipe
[1, 3, 4, 2] | reverse_sort
# Just like any other pipe
# Strictly equivalent to:
[1, 3, 4, 2] | reverse | sort
# as if P is replaced by [1, 3, 4, 2]
Have fun!
Todos
- add full type annotation support
- piping (dunder ror) can be typed easily
- there is seemingly no way to type varargs currying (supported by the original
pipelibrary) - use classes instead of functions for full type support??
- alternative implementation on
chunkfor sequences (supports slicing)
Metadata
Release files for morepipes 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| morepipes-1.0.4.tar.gz | 5.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| morepipes-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.1 kB
Release files / morepipes-1.0.4.tar.gz
| Download URL | morepipes-1.0.4.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f98f214f2156895bdccb3e0011bdb369472933fff437b183c7f0a51a6960c06
|
|
BLAKE2b-256 checksum How to use checksums |
0f3fece5553244e88792071dc8c489ae3942191a109279bb8642b669aa1b04ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Release files / morepipes-1.0.4-py3-none-any.whl
| Download URL | morepipes-1.0.4-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77acacb6abadb70dff8f1f0b05117c0d952d9c2af58145b14b1a406bdb384364
|
|
BLAKE2b-256 checksum How to use checksums |
d968b32c20792fa8cfc5c3c398520fc043de80c59a28a77ec7d9e7958bb2a3ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|