Skip to content

lazyfunc

Operations between callables, with lazy evaluation.

ci docs pypi


Installation

To install lazyfunc, use pip to install the latest version from PyPI.

$ pip install lazyfunc

Usage

Below is a short demo of lazyfunc. Arbitrary operations can be applied to the functions, even between each other. Function evaluation can be deferred until after the final function is constructed.

>>> from lazyfunc import LazyFunc

>>> @LazyFunc
... def f(x):
...     return 2 * x

>>> @LazyFunc
... def g(x):
...     return x ** 2

>>> combined_function = f * (g + 2) ** 2
>>> combined_function
LazyFunc(f * (g + 2) ** 2)

>>> combined_function(1) == 18
True

See the example for a more motivating use case.

Contributing

All contributions are welcome! Please raise an issue or make a pull request.