Class LambdaIterable<A>
- java.lang.Object
-
- com.jnape.palatable.lambda.traversable.LambdaIterable<A>
-
- Type Parameters:
A- theIterableelement type
- All Implemented Interfaces:
Applicative<A,LambdaIterable<?>>,Functor<A,LambdaIterable<?>>,Monad<A,LambdaIterable<?>>,MonadRec<A,LambdaIterable<?>>,Traversable<A,LambdaIterable<?>>
public final class LambdaIterable<A> extends java.lang.Object implements MonadRec<A,LambdaIterable<?>>, Traversable<A,LambdaIterable<?>>
- See Also:
LambdaMap
-
-
Constructor Summary
Constructors Modifier Constructor Description privateLambdaIterable(java.lang.Iterable<? extends A> as)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <B> LambdaIterable<B>discardL(Applicative<B,LambdaIterable<?>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.<B> LambdaIterable<A>discardR(Applicative<B,LambdaIterable<?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.static <A> LambdaIterable<A>empty()Construct an emptyLambdaIterableby wrappingCollections.emptyList().booleanequals(java.lang.Object other)<B> LambdaIterable<B>flatMap(Fn1<? super A,? extends Monad<B,LambdaIterable<?>>> f)Chain dependent computations that may continue or short-circuit based on previous results.<B> LambdaIterable<B>fmap(Fn1<? super A,? extends B> fn)Covariantly transmute this functor's parameter using the given mapping function.inthashCode()<B> Lazy<LambdaIterable<B>>lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,LambdaIterable<?>>> lazyAppFn)Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.<B> LambdaIterable<B>pure(B b)Lift the valuebinto this applicative functor.static Pure<LambdaIterable<?>>pureLambdaIterable()The canonicalPureinstance forLambdaIterable.<B> LambdaIterable<B>trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,LambdaIterable<?>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<B,App extends Applicative<?,App>,TravB extends Traversable<B,LambdaIterable<?>>,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.java.lang.Iterable<A>unwrap()Unwrap the underlyingIterable.static <A> LambdaIterable<A>wrap(java.lang.Iterable<? extends A> as)Wrap anIterablein aLambdaIterable.<B> LambdaIterable<B>zip(Applicative<Fn1<? super A,? extends B>,LambdaIterable<?>> appFn)Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
-
-
Field Detail
-
as
private final java.lang.Iterable<A> as
-
-
Constructor Detail
-
LambdaIterable
private LambdaIterable(java.lang.Iterable<? extends A> as)
-
-
Method Detail
-
unwrap
public java.lang.Iterable<A> unwrap()
Unwrap the underlyingIterable.- Returns:
- the wrapped
Iterable
-
fmap
public <B> LambdaIterable<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,LambdaIterable<?>>- Specified by:
fmapin interfaceFunctor<A,LambdaIterable<?>>- Specified by:
fmapin interfaceMonad<A,LambdaIterable<?>>- Specified by:
fmapin interfaceMonadRec<A,LambdaIterable<?>>- Specified by:
fmapin interfaceTraversable<A,LambdaIterable<?>>- Type Parameters:
B- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
pure
public <B> LambdaIterable<B> pure(B b)
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<A,LambdaIterable<?>>- Specified by:
purein interfaceMonad<A,LambdaIterable<?>>- Specified by:
purein interfaceMonadRec<A,LambdaIterable<?>>- Type Parameters:
B- the type of the returned applicative's parameter- Parameters:
b- the value- Returns:
- an instance of this applicative over b
-
zip
public <B> LambdaIterable<B> zip(Applicative<Fn1<? super A,? extends B>,LambdaIterable<?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.In this case, calculate the cartesian product of applications of all functions in
appFnto all values wrapped by thisLambdaIterable.- Specified by:
zipin interfaceApplicative<A,LambdaIterable<?>>- Specified by:
zipin interfaceMonad<A,LambdaIterable<?>>- Specified by:
zipin interfaceMonadRec<A,LambdaIterable<?>>- Type Parameters:
B- the new parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the zipped LambdaIterable
-
lazyZip
public <B> Lazy<LambdaIterable<B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,LambdaIterable<?>>> lazyAppFn)
Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. This is useful for applicatives that support lazy evaluation and early termination.- Specified by:
lazyZipin interfaceApplicative<A,LambdaIterable<?>>- Specified by:
lazyZipin interfaceMonad<A,LambdaIterable<?>>- Specified by:
lazyZipin interfaceMonadRec<A,LambdaIterable<?>>- Type Parameters:
B- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe,Either
-
discardL
public <B> LambdaIterable<B> discardL(Applicative<B,LambdaIterable<?>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<A,LambdaIterable<?>>- Specified by:
discardLin interfaceMonad<A,LambdaIterable<?>>- Specified by:
discardLin interfaceMonadRec<A,LambdaIterable<?>>- Type Parameters:
B- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
public <B> LambdaIterable<A> discardR(Applicative<B,LambdaIterable<?>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<A,LambdaIterable<?>>- Specified by:
discardRin interfaceMonad<A,LambdaIterable<?>>- Specified by:
discardRin interfaceMonadRec<A,LambdaIterable<?>>- Type Parameters:
B- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-
flatMap
public <B> LambdaIterable<B> flatMap(Fn1<? super A,? extends Monad<B,LambdaIterable<?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMapin interfaceMonad<A,LambdaIterable<?>>- Specified by:
flatMapin interfaceMonadRec<A,LambdaIterable<?>>- Type Parameters:
B- the resulting monad parameter type- Parameters:
f- the dependent computation over A- Returns:
- the new monad instance
-
trampolineM
public <B> LambdaIterable<B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,LambdaIterable<?>>> 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,LambdaIterable<?>>- 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
-
traverse
public <B,App extends Applicative<?,App>,TravB extends Traversable<B,LambdaIterable<?>>,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,LambdaIterable<?>>- 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
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
wrap
public static <A> LambdaIterable<A> wrap(java.lang.Iterable<? extends A> as)
Wrap anIterablein aLambdaIterable.- Type Parameters:
A- the Iterable element type- Parameters:
as- the Iterable- Returns:
- the Iterable wrapped in a
LambdaIterable
-
empty
public static <A> LambdaIterable<A> empty()
Construct an emptyLambdaIterableby wrappingCollections.emptyList().- Type Parameters:
A- the Iterable element type- Returns:
- an empty
LambdaIterable
-
pureLambdaIterable
public static Pure<LambdaIterable<?>> pureLambdaIterable()
The canonicalPureinstance forLambdaIterable.- Returns:
- the
Pureinstance
-
-