trcks.fp.monads.identity
Functions for the identity monad.
Provides utilities for functional composition of synchronous functions.
tap(f)
Turn synchronous function into a function that returns its input.
Parameters:
-
f
(Callable[[_T], object]
) –The synchronous function to be transformed into a function that returns its input.
Returns:
-
Callable[[_T], _T]
–The given function transformed into a function that returns its input.
Example
>>> from collections.abc import Callable
>>> from trcks.fp.monads import identity as i
>>> log_and_pass_on: Callable[[object], object] = i.tap(
... lambda o: print(f"Received object {o}.")
... )
>>> output = log_and_pass_on(42)
Received object 42.
>>> output
42
Source code in src/trcks/fp/monads/identity.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|