fptools.function¶
FP tools for functions¶
FP utilities to manipulate and partially apply functions
function swap - Swap the arguments of a 2 argument function
function sequenced - Convert function to take a sequence of its arguments
function negate - Transforms a predicate to its negation
function partial - Returns a partially applied function
- pythonic_fp.fptools.function.negate(f: Callable[[P], bool]) Callable[[P], bool] ¶
Negate predicate¶
Take a predicate and return its negation.
- param f:
a function
f
which returns a bool- returns:
the function
not f
- pythonic_fp.fptools.function.partial(f: Callable[[P], R], *args: Any) Callable[[...], R] ¶
Partial application¶
Partially apply arguments to a function, left to right.
type-wise the only thing guaranteed is the return type
best practice is to cast the result immediately
- pythonic_fp.fptools.function.sequenced(f: Callable[[...], R]) Callable[[tuple[Any]], R] ¶
Multi-to-single valued¶
Convert a function with arbitrary positional arguments to one taking a tuple of the original arguments.
was awaiting typing and mypy “improvements” to ParamSpec
return type: Callable[tuple[P.args], R] ???
return type: Callable[[tuple[P.args]], R] ???
TODO: Look into replacing this function with a Callable class?