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 Object
implements MonadRec<A, LambdaIterable<?>>, Traversable<A, LambdaIterable<?>>
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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().boolean<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> 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<?>> 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.unwrap()Unwrap the underlyingIterable.static <A> LambdaIterable<A> 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 Details
-
as
-
-
Constructor Details
-
LambdaIterable
-
-
Method Details
-
unwrap
-
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:
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
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
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:
-
discardL
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
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
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:
-
traverse
public <B, App extends Applicative<?,App>, TravB extends Traversable<B, LambdaIterable<?>>, AppTrav extends Applicative<TravB, AppTrav traverseApp>> (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
-
hashCode
-
wrap
Wrap anIterablein aLambdaIterable.- Type Parameters:
A- the Iterable element type- Parameters:
as- the Iterable- Returns:
- the Iterable wrapped in a
LambdaIterable
-
empty
Construct an emptyLambdaIterableby wrappingCollections.emptyList().- Type Parameters:
A- the Iterable element type- Returns:
- an empty
LambdaIterable
-
pureLambdaIterable
The canonicalPureinstance forLambdaIterable.- Returns:
- the
Pureinstance
-