apfel.core.common
Common yet miscellaneous utilities functions.
API#
Functions
| Name | Description |
|---|---|
apply | Applies a single-argument function to a value. |
identity | Returns the sole argument passed to it doing nothing. |
imperative | Returns the last expression passed into the function. |
not_none | Type narrowing: assert the value isn't None. |
pipe | Pipes a value through a sequence of functions. |
todo | Marks an unimplemented location that might be implemented in the future. |
unimplemented | Marks an unimplemented location that might not be implemented in the future. |
applyfunction#
def apply(value: T, func: Callable[[T], R], /) -> RApplies a single-argument function to a value.
For chained calls, see pipe.
See also from Python 2.7.apply
This function is different from Value.apply,
which is an implementation of Applicative
who requires the function to be wrapped in Value.
In contrast, this function accepts arbitrary callables.
This function is exposed in the package namespace and the builtins namespace.
Parameters
| Name | Type | Description |
|---|---|---|
value | T | The value to be passed to the function. |
func | Callable[[T], R] | The function to apply. |
Returns
R- The result of applying the function to the value.
identityfunction#
def identity(value: T, /) -> TReturns the sole argument passed to it doing nothing.
This function is exposed in the package namespace and the builtins namespace.
Parameters
| Name | Type | Description |
|---|---|---|
value | T | Any object. |
Returns
T- The same object passed to it.
imperativefunction#
def imperative(*exprs: *tuple[*Ts, R]) -> RReturns the last expression passed into the function.
If no expression are passed, returns None, per Python’s convention.
This function is exposed in the package namespace and the builtins namespace.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
*exprs | *tuple[*Ts, R] | () | Any number of expressions. |
Returns
R- The last expression passed into the function.
not_nonefunction#
def not_none(value: T | None, /) -> TType narrowing: assert the value isn’t None.
This function is exposed in the package namespace.
Parameters
| Name | Type | Description |
|---|---|---|
value | T | Any value that type-checked to be None,
but guarantees to be non-None. |
Returns
T- The same value passed to it.
Raises
ValueError- if the input is actually
None.
pipefunction#
def pipe(value: T | Any, /, *funcs: Callable[[T], T] | *tuple[*tuple[Callable[[Any], Any], ...], Callable[[Any], R]] | Callable[[Any], Any]) -> T | T1 | T2 | T3 | T4 | R | AnyPipes a value through a sequence of functions.
For single function application, see apply.
See also Value.update,
FunctionObject.__rand__.
See also &, |> or roughly %>%.
This function is exposed in the package namespace and the builtins namespace.
Parameters
Returns
AnyT | T1 | T2 | T3 | T4 | R | Any- The final result after applying all functions.
todofunction#
def todo(message: str | None = None, /) -> NoReturnMarks an unimplemented location that might be implemented in the future.
See todo! for usage.
This function is exposed in the package namespace and the builtins namespace.
Raises
NotImplementedError- Always.
unimplementedfunction#
def unimplemented(message: str | None = None, /) -> NoReturnMarks an unimplemented location that might not be implemented in the future.
See unimplemented! for usage.
This function is exposed in the package namespace and the builtins namespace.
Raises
NotImplementedError- Always.
