A lightweight package that contains pipe operators and functional tools
Project description
Pipefun
A simple, lightweighted, zero dependency python piping package.
Install
pip install pipefun
Usage
from pipefun import Pipable, out
from pipefun.Functionals import square
add_to = lambda a: lambda b: a + b # a curried **add** function
output = ~(x >> add_to(3) >> square)
print(output) # 36
The >> operator pushes a Pipable into a function and return a new Pipable with the return value of the function.
The ~ operator pulls the value in a Pipable
Note that Pipable is immutable, so the returned Pipable doesn't equal the input and is a new one
x_out = x >> add_to(3) >> square
print(x_out == x) # False
print(~x_out == ~x) # False
Pipe merging
In daily use case, it's very possible that functions take more than 1 arg. To handle this, Pipable can store more than 1 values and plug them into a function when needed.
We use the | operator to merge Pipables. In Python, it has lower priority than >>.
x = Pipable(3)
y = Pipable(5)
out = x >> square # Pipable(9)
# merge two Pipables together
out = out | y # Pipable(9, 5)
# plug the pipes into a two args function
out = out >> add # Pipable(14)
print(~out) # 14
Alternatively, in one line.
out = ( x >> square | y) >> add # Pipable(14)
print(~out) # 14
Let's discard the ~ operator
There is a special function in Pipable package that do nothing. If a Pipable is piped into it, same thing will happen with what the ~ operator do.
from pipefun import Pipable, out
x = Pipable(2)
y = x >> square >> out
print(y) # 4
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pipefun-0.0.7.tar.gz.
File metadata
- Download URL: pipefun-0.0.7.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bc8a763d3b1b139a10ba89d3b09303ef3c2f936bf18dfadd9a3459291d35ed0
|
|
| MD5 |
ac50726d78c5a5af7b22ebf1b32d57ac
|
|
| BLAKE2b-256 |
e6ac0eb150254ec78355d060ae5fe4e705cee04b32bd24140ae0203e4030979f
|
File details
Details for the file pipefun-0.0.7-py3-none-any.whl.
File metadata
- Download URL: pipefun-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e88e2209ab37d3fd38613e185eb55a2b9b3886da1bc5a41a499697b9d5ae3b8
|
|
| MD5 |
e1b6dabf6143c413d2d99165f66aeb9e
|
|
| BLAKE2b-256 |
3aba8761df36f7ddf05a132e5572b46eb65710ea1db713404f7d2ce629b3fc92
|