Package fj.data
Class Eval<A>
java.lang.Object
fj.data.Eval<A>
- Direct Known Subclasses:
Eval.Always
,Eval.Later
,Eval.Now
,Eval.TrampolineEval
Eval
is an abstraction over different models of evaluation.
The data constructors:
Now
- the value is evaluated immediately.Later
- the value is evaluated only once when it's requested (lazy evaluation).Always
- the value is evaluated every time when it's requested.
Later
and Always
are lazy computations, while Now
is eager.- Version:
- %build.number%
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Represents a lazy computation that is evaluated every time when it's requested.private static final class
private static final class
private static final class
Represents a lazy computation that is evaluated only once.private static final class
Represents an eager computation.private static final class
private static class
A helper abstraction that allows to perform recursive lazy transformations in O(1) stack space. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> Eval
<A> Constructs a lazy evaluation without caching.(package private) abstract Eval.TrampolineEval
<A> Transforms the current instance into a trampoline instance.final <B> Eval
<B> static <A> Eval
<A> final <B> Eval
<B> Alias forbind(F)
.static <A> Eval
<A> Constructs a lazy evaluation with caching.final <B> Eval
<B> static <A> Eval
<A> now
(A a) Constructs an eager evaluation by wrapping the given value.abstract A
value()
Evaluates the computation and return its result.
-
Constructor Details
-
Eval
public Eval()
-
-
Method Details
-
now
Constructs an eager evaluation by wrapping the given value.- Parameters:
a
- the evaluated value.- Returns:
- an eval with computed value.
-
later
Constructs a lazy evaluation with caching.- Parameters:
a
- the supplier that evaluates a value.- Returns:
- a lazy evaluation.
-
always
Constructs a lazy evaluation without caching.- Parameters:
a
- the supplier that evaluates a value.- Returns:
- a lazy evaluation.
-
defer
-
value
Evaluates the computation and return its result. Depending on whether the current instance is lazy or eager the computation may or may not happen at this point.- Returns:
- a result of this computation.
-
map
TransformsEval
into aEval
using the given function. Note: the computation of the given transformation is always lazy, even if it invoked for an eagerNow
instance. This computation is performed in O(1) stack space.- Parameters:
f
- the transformation function.- Returns:
- a transformed evaluation.
-
flatMap
Alias forbind(F)
. -
bind
TransformsEval
into aEval
using the given function that directly producesEval
. Note: the computation of the given transformation is always lazy, even if it invoked for an eagerNow
instance. This computation is performed in O(1) stack space.- Parameters:
f
- the transformation function.- Returns:
- a transformed evaluation.
-
asTrampoline
Transforms the current instance into a trampoline instance.
-