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
public abstract class Lazy<A> extends java.lang.Object implements MonadRec<A,Lazy<?>>, Traversable<A,Lazy<?>>
AMonadrepresenting a lazily-computed value. Stack-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLazy.Compose<A>private static classLazy.Later<A>
-
Constructor Summary
Constructors Modifier Constructor Description privateLazy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <B> Lazy<B>discardL(Applicative<B,Lazy<?>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.<B> Lazy<A>discardR(Applicative<B,Lazy<?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.booleanequals(java.lang.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.inthashCode()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 valuebinto this applicative functor.static Pure<Lazy<?>>pureLazy()java.lang.StringtoString()<B> Lazy<B>trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,Lazy<?>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<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)Applyfnto 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 Avalue()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.
-
-
-
Method Detail
-
value
public abstract A value()
Returns the value represented by this lazy computation.- Returns:
- the value
-
flatMap
public <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.
-
traverse
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)
Applyfnto 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:
traversein 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
public final <B> Lazy<B> pure(B b)
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<A,Lazy<?>>- Specified by:
purein interfaceMonad<A,Lazy<?>>- Specified by:
purein interfaceMonadRec<A,Lazy<?>>- Type Parameters:
B- the type of the returned applicative's parameter- Parameters:
b- the value- Returns:
- an instance of this applicative over b
-
fmap
public final <B> Lazy<B> fmap(Fn1<? super A,? extends B> fn)
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:
fmapin interfaceApplicative<A,Lazy<?>>- Specified by:
fmapin interfaceFunctor<A,Lazy<?>>- Specified by:
fmapin interfaceMonad<A,Lazy<?>>- Specified by:
fmapin interfaceMonadRec<A,Lazy<?>>- Specified by:
fmapin 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
public <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.- Specified by:
zipin interfaceApplicative<A,Lazy<?>>- Specified by:
zipin interfaceMonad<A,Lazy<?>>- Specified by:
zipin interfaceMonadRec<A,Lazy<?>>- Type Parameters:
B- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
discardL
public final <B> Lazy<B> discardL(Applicative<B,Lazy<?>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.
-
discardR
public final <B> Lazy<A> discardR(Applicative<B,Lazy<?>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.
-
trampolineM
public <B> Lazy<B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,Lazy<?>>> fn)
Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.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:
trampolineMin interfaceMonadRec<A,Lazy<?>>- Type Parameters:
B- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
for a basic implementation,for a implementation,for an implementation leveraging an already stack-safe,for a implementation
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
lazy
public static <A> Lazy<A> lazy(A value)
Lift a pure value into a lazy computation.- Type Parameters:
A- the value type- Parameters:
value- the value- Returns:
- the new
Lazy
-
lazy
public static <A> Lazy<A> lazy(Fn0<A> fn0)
Wrap a computation in a lazy computation.- Type Parameters:
A- the value type- Parameters:
fn0- the computation- Returns:
- the new
Lazy
-
-