Skip to content

apfel.core.common

Common yet miscellaneous utilities functions.

API#

Functions

NameDescription
applyApplies a single-argument function to a value.
identityReturns the sole argument passed to it doing nothing.
imperativeReturns the last expression passed into the function.
not_noneType narrowing: assert the value isn't None.
pipePipes a value through a sequence of functions.
todoMarks an unimplemented location that might be implemented in the future.
unimplementedMarks an unimplemented location that might not be implemented in the future.

applyfunction#

def apply(value: T, func: Callable[[T], R], /) -> R

Applies a single-argument function to a value. For chained calls, see pipe.

See also apply from Python 2.7.

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

NameTypeDescription
valueTThe value to be passed to the function.
funcCallable[[T], R]The function to apply.

Returns

R
The result of applying the function to the value.

identityfunction#

def identity(value: T, /) -> T

Returns the sole argument passed to it doing nothing.

This function is exposed in the package namespace and the builtins namespace.

Parameters

NameTypeDescription
valueTAny object.

Returns

T
The same object passed to it.

imperativefunction#

def imperative(*exprs: *tuple[*Ts, R]) -> R

Returns 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

NameTypeDefaultDescription
*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, /) -> T

Type narrowing: assert the value isn’t None.

This function is exposed in the package namespace.

Parameters

NameTypeDescription
valueTAny 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 | Any

Pipes 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

NameTypeDefaultDescription
valueTrequiredThe initial value to be piped.
*funcsCallable[[Any], Any]()A sequence of functions to apply to the value.

Returns

AnyT | T1 | T2 | T3 | T4 | R | Any
The final result after applying all functions.

todofunction#

def todo(message: str | None = None, /) -> NoReturn

Marks 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.

Parameters

NameTypeDefaultDescription
messagestr | NoneNoneThe extra message to be displayed.

Raises

NotImplementedError
Always.

unimplementedfunction#

def unimplemented(message: str | None = None, /) -> NoReturn

Marks 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.

Parameters

NameTypeDefaultDescription
messagestr | NoneNoneThe extra message to be displayed.

Raises

NotImplementedError
Always.