public abstract class Eval<A>
extends java.lang.Object
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.Constructor and Description |
---|
Eval() |
Modifier and Type | Method and Description |
---|---|
static <A> Eval<A> |
always(F0<A> a)
Constructs a lazy evaluation without caching.
|
<B> Eval<B> |
bind(F<A,Eval<B>> f)
|
static <A> Eval<A> |
defer(F0<Eval<A>> a)
|
<B> Eval<B> |
flatMap(F<A,Eval<B>> f)
Alias for
bind(F) . |
static <A> Eval<A> |
later(F0<A> a)
Constructs a lazy evaluation with caching.
|
<B> Eval<B> |
map(F<A,B> f)
|
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.
|
public static <A> Eval<A> now(A a)
a
- the evaluated value.public static <A> Eval<A> later(F0<A> a)
a
- the supplier that evaluates a value.public static <A> Eval<A> always(F0<A> a)
a
- the supplier that evaluates a value.public abstract A value()
public final <B> Eval<B> map(F<A,B> f)
Eval
into a Eval
using
the given function.
Note: the computation of the given transformation is always lazy,
even if it invoked for an eager Now
instance. This computation
is performed in O(1) stack space.f
- the transformation function.public final <B> Eval<B> bind(F<A,Eval<B>> f)
Eval
into a Eval
using
the given function that directly produces Eval
.
Note: the computation of the given transformation is always lazy,
even if it invoked for an eager Now
instance. This computation
is performed in O(1) stack space.f
- the transformation function.