A
- the value typepublic abstract class Lazy<A> extends Object implements MonadRec<A,Lazy<?>>, Traversable<A,Lazy<?>>
Monad
representing a lazily-computed value. Stack-safe.Modifier and Type | Method and Description |
---|---|
<B> Lazy<B> |
discardL(Applicative<B,Lazy<?>> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
<B> Lazy<A> |
discardR(Applicative<B,Lazy<?>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
boolean |
equals(Object other) |
<B> Lazy<B> |
flatMap(Fn1<? super A,? extends Monad<B,Lazy<?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
|
<B> Lazy<B> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
int |
hashCode() |
static <A> Lazy<A> |
lazy(A value)
Lift a pure value into a lazy computation.
|
static <A> Lazy<A> |
lazy(Fn0<A> fn0)
Wrap a computation in a lazy computation.
|
<B> Lazy<B> |
pure(B b)
Lift the value
b into this applicative functor. |
static Pure<Lazy<?>> |
pureLazy()
|
String |
toString() |
<B> Lazy<B> |
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,Lazy<?>>> fn)
Given some operation yielding a
RecursiveResult inside this MonadRec , internally trampoline the
operation until it yields a termination instruction. |
<B,App extends Applicative<?,App>,TravB extends Traversable<B,Lazy<?>>,AppTrav extends Applicative<TravB,App>> |
traverse(Fn1<? super A,? extends Applicative<B,App>> fn,
Fn1<? super TravB,? extends AppTrav> pure)
Apply
fn to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function. |
abstract A |
value()
Returns the value represented by this lazy computation.
|
<B> Lazy<B> |
zip(Applicative<Fn1<? super A,? extends B>,Lazy<?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using
whatever application semantics the current applicative supports.
|
public abstract A value()
public <B> Lazy<B> flatMap(Fn1<? super A,? extends Monad<B,Lazy<?>>> f)
public <B,App extends Applicative<?,App>,TravB extends Traversable<B,Lazy<?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super A,? extends Applicative<B,App>> fn, Fn1<? super TravB,? extends AppTrav> pure)
fn
to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function.traverse
in interface Traversable<A,Lazy<?>>
B
- the resulting element typeApp
- the result applicative typeTravB
- this Traversable instance over BAppTrav
- the full inferred resulting type from the traversalfn
- the function to applypure
- the applicative pure functionpublic final <B> Lazy<B> pure(B b)
b
into this applicative functor.public final <B> Lazy<B> fmap(Fn1<? super A,? extends B> fn)
fmap
in interface Applicative<A,Lazy<?>>
fmap
in interface Functor<A,Lazy<?>>
fmap
in interface Monad<A,Lazy<?>>
fmap
in interface MonadRec<A,Lazy<?>>
fmap
in interface Traversable<A,Lazy<?>>
B
- the new parameter typefn
- the mapping functionpublic <B> Lazy<B> zip(Applicative<Fn1<? super A,? extends B>,Lazy<?>> appFn)
public final <B> Lazy<B> discardL(Applicative<B,Lazy<?>> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.public final <B> Lazy<A> discardR(Applicative<B,Lazy<?>> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.public <B> Lazy<B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,Lazy<?>>> fn)
RecursiveResult
inside this MonadRec
, internally trampoline the
operation until it yields a termination
instruction.
Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
trampolineM
in interface MonadRec<A,Lazy<?>>
B
- the ultimate resulting carrier typefn
- the function to internally trampolineMonadRec
for a basic implementation
,
for a {@link CoProduct2 coproduct} implementation
,
for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}
,
for a {@link MonadT monad transformer} implementation
public static <A> Lazy<A> lazy(A value)
A
- the value typevalue
- the valueLazy
public static <A> Lazy<A> lazy(Fn0<A> fn0)
A
- the value typefn0
- the computationLazy