module documentation

Types and higher order functions for function composition.

Example

Sequentially apply two functions to one input value in three different ways:

>>> def to_length_string(n: int) -> str:
...     return f"Length: {n}"
...
>>> input_ = "Hello, world!"
>>> to_length_string(len(input_))
'Length: 13'
>>> get_length_string = compose((len, to_length_string))
>>> get_length_string(input_)
'Length: 13'
>>> pipe((input_, len, to_length_string))
'Length: 13'
Function compose Compose a tuple of compatible functions from first to last.
Function pipe Evaluate a Pipeline.
Type Alias Composable Up to seven compatible functions that can be applied sequentially from first to last.
Type Alias Composable1 A single function.
Type Alias Composable2 Two compatible functions that can be applied sequentially from first to last.
Type Alias Composable3 Three compatible functions that can be applied sequentially from first to last.
Type Alias Composable4 Four compatible functions that can be applied sequentially from first to last.
Type Alias Composable5 Five compatible functions that can be applied sequentially from first to last.
Type Alias Composable6 Six compatible functions that can be applied sequentially from first to last.
Type Alias Composable7 Seven compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline A single value followed by up to seven compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline0 A single value.
Type Alias Pipeline1 A single value followed by a single compatible function that can be applied.
Type Alias Pipeline2 A single value followed by two compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline3 A single value followed by three compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline4 A single value followed by four compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline5 A single value followed by five compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline6 A single value followed by six compatible functions that can be applied sequentially from first to last.
Type Alias Pipeline7 A single value followed by seven compatible functions that can be applied sequentially from first to last.
Constant _IN Undocumented
Constant _OUT Undocumented
Constant _T0 Undocumented
Constant _T1 Undocumented
Constant _T2 Undocumented
Constant _T3 Undocumented
Constant _T4 Undocumented
Constant _T5 Undocumented
Constant _T6 Undocumented
Constant _T7 Undocumented
def compose(c: Composable[_IN, _T1, _T2, _T3, _T4, _T5, _T6, _OUT]) -> Callable[[_IN], _OUT]: (source)

Compose a tuple of compatible functions from first to last.

Example

>>> get_length_string = compose((len, lambda n: f"Length: {n}"))
>>> get_length_string("Hello, world!")
'Length: 13'
Parameters
c:Composable[_IN, _T1, _T2, _T3, _T4, _T5, _T6, _OUT]Compatible functions that can be applied sequentially from first to last.
Returns
Callable[[_IN], _OUT]Function that applies the given functions from first to last.
def pipe(p: Pipeline[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _OUT]) -> _OUT: (source)

Evaluate a Pipeline.

Example

>>> pipe(("Hello, world!", len, lambda n: f"Length: {n}"))
'Length: 13'
Parameters
p:Pipeline[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _OUT]Single value followed by up to seven compatible functions that can be applied sequentially from first to last.
Returns
_OUTResult of sequentially applying the given functions from first to last to the given value.
Composable: TypeAlias = (source)

Up to seven compatible functions that can be applied sequentially from first to last.

Value
Composable7[_IN, _T1, _T2, _T3, _T4, _T5, _T6, _OUT] | Composable6[_IN,
                                                                   _T1,
                                                                   _T2,
                                                                   _T3,
                                                                   _T4,
                                                                   _T5,
                                                                   _OUT] | Composable5
...
Composable1: TypeAlias = (source)

A single function.

Value
tuple[Callable[[_T0], _T1]]
Composable2: TypeAlias = (source)

Two compatible functions that can be applied sequentially from first to last.

Value
tuple[Callable[[_T0], _T1], Callable[[_T1], _T2]]
Composable3: TypeAlias = (source)

Three compatible functions that can be applied sequentially from first to last.

Value
tuple[Callable[[_T0], _T1], Callable[[_T1], _T2], Callable[[_T2], _T3]]
Composable4: TypeAlias = (source)

Four compatible functions that can be applied sequentially from first to last.

Value
tuple[Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4]]
Composable5: TypeAlias = (source)

Five compatible functions that can be applied sequentially from first to last.

Value
tuple[Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4],
      Callable[[_T4], _T5]]
Composable6: TypeAlias = (source)

Six compatible functions that can be applied sequentially from first to last.

Value
tuple[Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4],
      Callable[[_T4], _T5],
      Callable[[_T5], _T6]]
Composable7: TypeAlias = (source)

Seven compatible functions that can be applied sequentially from first to last.

Value
tuple[Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4],
      Callable[[_T4], _T5],
      Callable[[_T5], _T6],
      Callable[[_T6], _T7]]
Pipeline: TypeAlias = (source)

A single value followed by up to seven compatible functions that can be applied sequentially from first to last.

Value
Pipeline7[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _OUT] | Pipeline6[_T0,
                                                               _T1,
                                                               _T2,
                                                               _T3,
                                                               _T4,
                                                               _T5,
                                                               _OUT] | Pipeline5
...
Pipeline0: TypeAlias = (source)

A single value.

Value
tuple[_T0]
Pipeline1: TypeAlias = (source)

A single value followed by a single compatible function that can be applied.

Value
tuple[_T0, Callable[[_T0], _T1]]
Pipeline2: TypeAlias = (source)

A single value followed by two compatible functions that can be applied sequentially from first to last.

Value
tuple[_T0, Callable[[_T0], _T1], Callable[[_T1], _T2]]
Pipeline3: TypeAlias = (source)

A single value followed by three compatible functions that can be applied sequentially from first to last.

Value
tuple[_T0, Callable[[_T0], _T1], Callable[[_T1], _T2], Callable[[_T2], _T3]]
Pipeline4: TypeAlias = (source)

A single value followed by four compatible functions that can be applied sequentially from first to last.

Value
tuple[_T0,
      Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4]]
Pipeline5: TypeAlias = (source)

A single value followed by five compatible functions that can be applied sequentially from first to last.

Value
tuple[_T0,
      Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4],
      Callable[[_T4], _T5]]
Pipeline6: TypeAlias = (source)

A single value followed by six compatible functions that can be applied sequentially from first to last.

Value
tuple[_T0,
      Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4],
      Callable[[_T4], _T5],
      Callable[[_T5], _T6]]
Pipeline7: TypeAlias = (source)

A single value followed by seven compatible functions that can be applied sequentially from first to last.

Value
tuple[_T0,
      Callable[[_T0], _T1],
      Callable[[_T1], _T2],
      Callable[[_T2], _T3],
      Callable[[_T3], _T4],
      Callable[[_T4], _T5],
      Callable[[_T5], _T6],
...

Undocumented

Value
TypeVar('_IN')

Undocumented

Value
TypeVar('_OUT')

Undocumented

Value
TypeVar('_T0')

Undocumented

Value
TypeVar('_T1')

Undocumented

Value
TypeVar('_T2')

Undocumented

Value
TypeVar('_T3')

Undocumented

Value
TypeVar('_T4')

Undocumented

Value
TypeVar('_T5')

Undocumented

Value
TypeVar('_T6')

Undocumented

Value
TypeVar('_T7')