Composition
pipe_once(inner: Unary[T, U], outer: Unary[U, R]) -> Unary[T, R]
Composes two functions from left to right into one function.
For instance, pipe_once(f, g)(x) is equivalent to g(f(x)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inner |
Unary[T, U]
|
The inner function. |
required |
outer |
Unary[U, R]
|
The outer function. |
required |
Returns:
| Type | Description |
|---|---|
Unary[T, R]
|
The composed function. |
Source code in src/funcs/composition.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
pipe(innermost: Unary[T, Any], *functions: Unary[Any, Any]) -> Unary[T, Any]
Composes multiple functions from left to right into one function.
For instance, pipe(f, g)(x) is equivalent to g(f(x)).
This function is equivalent to:
fold(innermost, pipe_once, functions)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
innermost |
Unary[T, Any]
|
The innermost function. |
required |
*functions |
Unary[Any, Any]
|
The rest of the functions. |
()
|
Returns:
| Type | Description |
|---|---|
Unary[T, Any]
|
The composed function. |
Source code in src/funcs/composition.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
compose_once(outer: Unary[U, R], inner: Unary[T, U]) -> Unary[T, R]
Composes two functions from right to left into one function.
For instance, compose_once(f, g)(x) is equivalent to f(g(x)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer |
Unary[U, R]
|
The outer function. |
required |
inner |
Unary[T, U]
|
The inner function. |
required |
Returns:
| Type | Description |
|---|---|
Unary[T, R]
|
The composed function. |
Source code in src/funcs/composition.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
compose(outermost: Unary[Any, T], *functions: Unary[Any, Any]) -> Unary[Any, T]
Composes multiple functions from right to left into one.
For instance, compose(f, g)(x) is equivalent to f(g(x)).
This function is equivalent to:
fold(outermost, compose_once, functions)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outermost |
Unary[Any, T]
|
The outermost function. |
required |
*functions |
Unary[Any, Any]
|
The rest of the functions. |
()
|
Returns:
| Type | Description |
|---|---|
Unary[Any, T]
|
The composed function. |
Source code in src/funcs/composition.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |