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 |
|
Up to seven compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single function. |
Type Alias |
|
Two compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
Three compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
Four compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
Five compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
Six compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
Seven compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single value followed by up to seven compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single value. |
Type Alias |
|
A single value followed by a single compatible function that can be applied. |
Type Alias |
|
A single value followed by two compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single value followed by three compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single value followed by four compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single value followed by five compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
A single value followed by six compatible functions that can be applied sequentially from first to last. |
Type Alias |
|
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[ | Compatible functions that can be applied sequentially from first to last. |
Returns | |
Callable[ | Function that applies the given functions from first to last. |
Evaluate a Pipeline
.
Example
>>> pipe(("Hello, world!", len, lambda n: f"Length: {n}")) 'Length: 13'
Parameters | |
p:Pipeline[ | Single value followed by up to seven compatible functions that can be applied sequentially from first to last. |
Returns | |
_OUT | Result of sequentially applying the given functions from first to last to the given value. |