pythonwrench.functools module¶
- class pythonwrench.functools.Compose[source]¶
- class pythonwrench.functools.Compose(fn0: Iterable[Callable[[T], T]], /)
- class pythonwrench.functools.Compose(fn0: Callable[[T], U], /)
- class pythonwrench.functools.Compose(fn0: Callable[[T], Any], fn1: Callable[[Any], U], /)
- class pythonwrench.functools.Compose(fn0: Callable[[T], Any], fn1: Callable[[Any], Any], fn2: Callable[[Any], U], /)
- class pythonwrench.functools.Compose(fn0: Callable[[T], Any], fn1: Callable[[Any], Any], fn2: Callable[[Any], Any], fn3: Callable[[Any], U], /)
- class pythonwrench.functools.Compose(fn0: Callable[[T], Any], fn1: Callable[[Any], Any], fn2: Callable[[Any], Any], fn3: Callable[[Any], Any], fn4: Callable[[Any], U], /)
- class pythonwrench.functools.Compose(*fns: Callable)
Bases:
Generic[T,U]Compose callables to chain calls sequentially.
-
pythonwrench.functools.filter_and_call(fn: Callable[[...], T], _fill_all_arguments: bool =
False, **kwargs: Any) T[source]¶ Call object only with the valid keyword arguments. Non-valid arguments are ignored.
- Arguments:
fn: Callable to call. _fill_all_arguments: If True, all arguments of fn must be provided in kwargs. defaults to False. **kwargs: Superset of arguments to pass to fn.
Name that does not match any argument of fn are ignored.
Examples:¶
>>> def f(x, y): >>> return x + y >>> filter_and_call(f, y=2, x=1) ... 3 >>> filter_and_call(f, y=2, x=1, z=0) # z is ignored ... 3
-
pythonwrench.functools.function_alias(alternative: Callable[[P], U], *, pre_fn: Callable[[...], Any] | None =
None, post_fn: Callable[[...], Any] | None =None) Callable[[...], Callable[[P], U]][source]¶ Decorator to wrap function aliases.
Example¶
>>> def f(a: int, b: str) -> str: >>> return a * b >>> @function_alias(f) >>> def g(*args, **kwargs): ... >>> f(2, "a") ... "aa" >>> g(3, "b") # calls function f() internally. ... "bbb"