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
Cut iterables
range(9) | take(5) | drop(2) | collect
Remove duplicates
a = [1, 3, 3, 1, 2, 4, 4, 2, 2, 2, 1, 4, 4, 3, 3, 1]
b = a | squeeze | collect
c = b | unique | collect
Manipulate iterations
range(9) | chunks(4)
range(9) | alternate
Side effects
range(9) | ... | inspect | ...
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
[1, 2, 3] | iall(iseven)
[1, 2, 3] | iany(iseven)
[1, 2, 3] | ilen
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
Using a partial pipe
[1, 3, 4, 2] | reverse_sort
[1, 3, 4, 2] | reverse | sort
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
pipe
library)
- use classes instead of functions for full type support??
- alternative implementation on
chunk
for sequences (supports slicing)