Functional Pipelines implemented in python
Project description
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 operator import add, mul
>>> from functional_pipeline import pipeline, tap
>>> result = pipeline(
... 10,
... [
... (add, 1),
... (mul, 2)
... ]
... )
>>> 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, lambda x: x + " Smith"),
... join(", "),
... ]
... )
>>> result
'John Smith, James Smith, Jamie Smith'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for functional_pipeline-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c8332932318c88d2a62bfa1212beead89eca03a240d0b14c93ffa39fc6b7678 |
|
MD5 | 5fc251af0cb65c650eb710bab9ac8ac6 |
|
BLAKE2b-256 | 7877d9cb7409e058299793c2cb095c2562a4a1af50f18ce971798dd5240bf079 |