Welcome to Functional Pipeline's Documentation!
| Documentation: | https://functional-pipeline.readthedocs.io/ |
|---|---|
| Source Code: | https://gitlab.com/mc706/functional-pipeline |
| Issue Tracker: | https://gitlab.com/mc706/functional-pipeline/issues |
| PyPI: | https://pypi.org/project/functional-pipeline/ |
Functional languages like Haskell, Elixir, and Elm have pipe functions that allow the results of one function to be passed to the next function.
Using functions from functools, we can build composition in python, however it is not
nearly as elegant as a well thought out pipeline.
This library is designed to make the creation of a functional pipeline easier in python.
from operators import add, multiply
from functional_pipeline import pipeline, tap
result = pipeline(
10,
[
(add, 1),
(multiply, 2)
]
)
print(result) # 22
This pattern can be extended for easily dealing with lists or generators.
from functional_pipeline import pipeline, String, join
names = [
"John",
"James",
"Bill",
"Tiffany",
"Jamie",
]
result = pipeline(
names,
[
(filter, String.startswith('J')),
(map, lamdba x: x + " Smith")
join(", ")
]
)
print(result) # "John Smith, James Smith, Jamie Smith"
Installation
This project is distributed via pip. To get started:
pip install functional-pipeline