Class Lazy<A>
java.lang.Object
com.jnape.palatable.lambda.functor.builtin.Lazy<A>
- Type Parameters:
A
- the value type
- All Implemented Interfaces:
Applicative<A,
,Lazy<?>> Functor<A,
,Lazy<?>> Monad<A,
,Lazy<?>> MonadRec<A,
,Lazy<?>> Traversable<A,
Lazy<?>>
- Direct Known Subclasses:
Lazy.Compose
,Lazy.Later
A
Monad
representing a lazily-computed value. Stack-safe.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <B> Lazy
<B> discardL
(Applicative<B, Lazy<?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.discardR
(Applicative<B, Lazy<?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.boolean
<B> Lazy
<B> Chain dependent computations that may continue or short-circuit based on previous results.final <B> Lazy
<B> 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> Wrap a computation in a lazy computation.final <B> Lazy
<B> pure
(B b) Lift the valueb
into this applicative functor.pureLazy()
toString()
<B> Lazy
<B> trampolineM
(Fn1<? super A, ? extends MonadRec<RecursiveResult<A, B>, Lazy<?>>> fn) Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<B,
App extends Applicative<?, App>, TravB extends Traversable<B, Lazy<?>>, AppTrav extends Applicative<TravB, App>>
AppTravtraverse
(Fn1<? super A, ? extends Applicative<B, App>> fn, Fn1<? super TravB, ? extends AppTrav> pure) Applyfn
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.
-
Constructor Details
-
Lazy
private Lazy()
-
-
Method Details
-
value
Returns the value represented by this lazy computation.- Returns:
- the value
-
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
traverse
public <B,App extends Applicative<?, AppTrav traverseApp>, TravB extends Traversable<B, Lazy<?>>, AppTrav extends Applicative<TravB, App>> (Fn1<? super A, ? extends Applicative<B, App>> fn, Fn1<? super TravB, ? extends AppTrav> pure) Applyfn
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.- Specified by:
traverse
in interfaceTraversable<A,
Lazy<?>> - Type Parameters:
B
- the resulting element typeApp
- the result applicative typeTravB
- this Traversable instance over BAppTrav
- the full inferred resulting type from the traversal- Parameters:
fn
- the function to applypure
- the applicative pure function- Returns:
- the traversed Traversable, wrapped inside an applicative
-
pure
Lift the valueb
into this applicative functor. -
fmap
Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.- Specified by:
fmap
in interfaceApplicative<A,
Lazy<?>> - Specified by:
fmap
in interfaceFunctor<A,
Lazy<?>> - Specified by:
fmap
in interfaceMonad<A,
Lazy<?>> - Specified by:
fmap
in interfaceMonadRec<A,
Lazy<?>> - Specified by:
fmap
in interfaceTraversable<A,
Lazy<?>> - Type Parameters:
B
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
zip
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. -
discardL
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects. -
discardR
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects. -
trampolineM
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
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.
- Specified by:
trampolineM
in interfaceMonadRec<A,
Lazy<?>> - Type Parameters:
B
- the ultimate resulting carrier type- Parameters:
fn
- the function to internally trampoline- Returns:
- the trampolined
MonadRec
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
lazy
Lift a pure value into a lazy computation.- Type Parameters:
A
- the value type- Parameters:
value
- the value- Returns:
- the new
Lazy
-
lazy
Wrap a computation in a lazy computation.- Type Parameters:
A
- the value type- Parameters:
fn0
- the computation- Returns:
- the new
Lazy
-
pureLazy
- Returns:
- the
Pure
instance
-