lazy¶
Lazy function evaluation
Non-strict delayed function evaluation.
class Lazy - Delay evaluation of single argument functions
function lazy - Delay evaluation of functions taking any number of arguments
function real_lazy - Caching version of
lazy.
- class pythonic_fp.fptools.lazy.Lazy¶
Bases:
GenericLazy (delayed) function evaluation
Delayed evaluation of a singled valued function.
Tip
Make a function “non-strict” by passing some of its arguments wrapped in Lazy instances.
- __init__(f: Callable[[D], R], d: D, pure: bool = True) None¶
initialize
Delayed evaluation of a single argument function.
- param f:
Single argument function.
- param d:
Argument to be passed to
f.- param pure:
If true, cache the result for future
evalmethod calls.- returns:
A Lazy instance which can evaluate
f(d)at a later time.
- __bool__() bool¶
bool
A Lazy becomes truthy when evaluated.
- returns:
Truewhen evaluated.- returns:
Falsewhen not evaluated.
- eval() None¶
evaluate
Evaluate function with its argument.
cache result or exception if
pure is Truereevaluate if
pure is False
- got_result() MayBe[bool]¶
Got valid result
Check if a valid result was obtained.
- returns:
MayBe()if not yet evaluated.- returns:
MayBe(True)if a result was gotten.- returns:
MayBe(False)if an exception was thrown.
- got_exception() MayBe[bool]¶
Exception raised
Check if exception thrown.
- returns:
MayBe()if not yet evaluated.- returns:
MayBe(True)if an exception was thrown.- returns:
MayBe(False)if exception not thrown.
- get(alt: R | None = None) R¶
get
Get result only if evaluated and no exceptions occurred, otherwise return an alternate value.
- param alt:
Optional alternate value to return if
Lazyis not evaluated or exceptional.- returns:
The successfully evaluated result or alt if given.
- raises ValueError:
if
Lazynot evaluated, or exceptional andaltnot given.
- pythonic_fp.fptools.lazy.lazy(f: Callable[[P], R], *args: P, **kwargs: P) Lazy[tuple[Any, ...], R]¶
delayed evaluations
Function returning a delayed evaluation of a function of an arbitrary number of positional arguments.
- param f:
Function whose evaluation is to be delayed.
- param args:
Positional arguments to be passed to
f.- param kwargs:
Any kwargs given are ignored.
- returns:
a
Lazyobject wrapping the evaluation off
- pythonic_fp.fptools.lazy.real_lazy(f: Callable[[P], R], *args: P, **kwargs: P) Lazy[tuple[Any, ...], R]¶
cached delayed evaluations
Function returning a delayed evaluation of a function of an arbitrary number of positional arguments. Evaluation is cached.
- param f:
Function whose evaluation is to be delayed.
- param args:
Positional arguments to be passed to
f.- param kwargs:
Any kwargs given are ignored.
- returns:
a
Lazyobject wrapping the evaluation off