Skip to content

Common#

Common yet miscellaneous utilities functions.

apply(value, func) #

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:

Name Type Description Default
value T

The value to be passed to the function.

required
func Callable[[T], R]

The function to apply.

required

Returns:

Name Type Description
out R

The result of applying the function to the value.

identity(value) #

Returns the sole argument passed to it doing nothing.

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

Parameters:

Name Type Description Default
value T

Any object.

required

Returns:

Name Type Description
value T

The same object passed to it.

imperative(*exprs) #

imperative() -> None
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:

Name Type Description Default
*exprs *tuple[*Ts, R]

Any number of expressions.

()

Returns:

Name Type Description
out R

The last expression passed into the function.

not_none(value) #

Type narrowing: assert the value isn't None.

This function is exposed in the package namespace.

Parameters:

Name Type Description Default
x T

Any value that type-checked to be None, but guarantees to be non-None.

required

Returns:

Name Type Description
out T

The same value passed to it.

Raises:

Type Description
ValueError

if the input is actually None.

pipe(value, /, *funcs) #

pipe(value: T) -> T
pipe(value: T, /, __func1: Callable[[T], T1]) -> T1
pipe(value: T, /, __func1: Callable[[T], T1], __func2: Callable[[T1], T2]) -> T2
pipe(value: T, /, __func1: Callable[[T], T1], __func2: Callable[[T1], T2], __func3: Callable[[T2], T3]) -> T3
pipe(value: T, /, __func1: Callable[[T], T1], __func2: Callable[[T1], T2], __func3: Callable[[T2], T3], __func4: Callable[[T3], T4]) -> T4
pipe(value: T, /, *funcs: Callable[[T], T]) -> T
pipe(value: T, /, __func1: Callable[[T], T1], __func2: Callable[[T1], T2], __func3: Callable[[T2], T3], __func4: Callable[[T3], T4], *funcs: *(tuple[*(tuple[Callable[[Any], Any], ...]), Callable[[Any], R]])) -> R
pipe(value: Any, /, *funcs: Callable[[Any], Any]) -> 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:

Name Type Description Default
value T

The initial value to be piped.

required
*funcs Callable[[Any], Any]

A sequence of functions to apply to the value.

()

Returns:

Name Type Description
out Any

The final result after applying all functions.

todo(message=None) #

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:

Name Type Description Default
message str | None

The extra message to be displayed.

None

Raises:

Type Description
NotImplementedError

Always.

unimplemented(message=None) #

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:

Name Type Description Default
message str | None

The extra message to be displayed.

None

Raises:

Type Description
NotImplementedError

Always.