aspis.common.pipe

aspis.common.pipe(first_func, *funcs)[source]

Performs left-to-right function composition. The first argument may have any arity; the remaining arguments must be unary.

See also compose

Parameters:
  • first_func (Callable[..., Any]) – First function which can be any arity.

  • *funcs (Callable[[Any], Any]) – List of functions to be composed.

Returns:

Left-to-right composed function.

Return type:

Callable

Examples

>>> times_two = multiply(2)
>>> add_two = add(2)
>>> add_then_multiply = pipe(add_two, times_two)
>>> result = add_then_multiply(3)  # returns 10