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], **kwargs: Any) T[source]¶
Call object only with the valid keyword arguments. Non-valid arguments 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]) 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"