other.pipeline

Attributes

T

Classes

Pipeline

Functional Programming implementation of a Pipeline with Unix Pipe Syntax.

Module Contents

class other.pipeline.Pipeline(f_ls: collections.abc.Sequence[collections.abc.Callable] | None = None)

Functional Programming implementation of a Pipeline with Unix Pipe Syntax. Instead of using the “dot” notation for applying a function on a given object, it uses | inspired from unix pipeline.

Examples:
>>> pipeline = Pipeline()
>>> pipeline = pipeline | (lambda x: x + 1) | (lambda x: x * 2)
>>> pipeline(1)
4
>>> pipeline = Pipeline() | (lambda x: x * x) | (lambda x: x - 3)
>>> pipeline(3)
6
>>> from functools import reduce
>>> def f1(ls): return map(lambda x: x**2, ls)
>>> def f2(ls): return filter(lambda x: x % 2 == 0, ls)
>>> def f3(ls): return reduce(lambda x, y: x + y, ls)
>>> pipeline = Pipeline() | f1 | f2 | f3
>>> pipeline([1, 2, 3, 4])
20
__call__(input_object: T, f_ls_: collections.abc.Sequence[collections.abc.Callable] | None = None) Any
__or__(other: collections.abc.Callable) Pipeline
_f_ls = []
other.pipeline.T