A utility for calling functions in pipelines.
Project description
Pipeline Functions
Pipeline Functions is a simple utility for calling functions in "pipelines", i.e. where the output from one function is automatically the input for the next. Here's an example showing how this works:
>>> from pipeline_func import f
>>> def keep_odd(items):
... return [x for x in items if x % 2 == 1]
>>> def keep_greater(items, threshold):
... return [x for x in items if x > threshold]
>>> range(10) | f(keep_odd) | f(keep_greater, 4)
[5, 7, 9]
Contrast this to the harder-to-read style required to call these same functions without this library:
>>> numbers = range(10)
>>> numbers = keep_odd(numbers)
>>> keep_greater(numbers, 4)
[5, 7, 9]
The only API provided by this library is the f
function. The first argument
should be a callable object. The remaining arguments can be arbitrary
positional or keyword arguments. Call the function by using the |
operator
as shown above. The output from the left-hand side of the operator will be the
first argument to the function. Any extra arguments provided to f()
will be
added after.
This library only works if each pipeline function has exactly one input and one
output. It also requires that the initial input object does not implement the
left |
operator for pipeline_func.PipelineFunc
objects. This should be true
for any well-behaved object, though.
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 Distribution
Built Distribution
Hashes for pipeline_func-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19d907d3a67c2fba4d392d1b3f3cf3452c6286952fcbbca3faa97ec3a4d4a60e |
|
MD5 | aa3406aaa20289e782f2508daafaa9dd |
|
BLAKE2b-256 | ad014ebe934406c4d66b22d3c60224427830f945594d86d7217a659ce44fa3f5 |