Class LambdaIterable<A>
- java.lang.Object
-
- com.jnape.palatable.lambda.traversable.LambdaIterable<A>
-
- Type Parameters:
A
- theIterable
element 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 private
LambdaIterable(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 thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<B> LambdaIterable<A>
discardR(Applicative<B,LambdaIterable<?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.static <A> LambdaIterable<A>
empty()
Construct an emptyLambdaIterable
by wrappingCollections.emptyList()
.boolean
equals(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.int
hashCode()
<B> Lazy<LambdaIterable<B>>
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,LambdaIterable<?>>> lazyAppFn)
Given alazy
instance 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 valueb
into this applicative functor.static Pure<LambdaIterable<?>>
pureLambdaIterable()
The canonicalPure
instance forLambdaIterable
.<B> LambdaIterable<B>
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,LambdaIterable<?>>> 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,LambdaIterable<?>>,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.java.lang.Iterable<A>
unwrap()
Unwrap the underlyingIterable
.static <A> LambdaIterable<A>
wrap(java.lang.Iterable<? extends A> as)
Wrap anIterable
in 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:
fmap
in interfaceApplicative<A,LambdaIterable<?>>
- Specified by:
fmap
in interfaceFunctor<A,LambdaIterable<?>>
- Specified by:
fmap
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
fmap
in interfaceMonadRec<A,LambdaIterable<?>>
- Specified by:
fmap
in 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 valueb
into this applicative functor.- Specified by:
pure
in interfaceApplicative<A,LambdaIterable<?>>
- Specified by:
pure
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
pure
in 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
appFn
to all values wrapped by thisLambdaIterable
.- Specified by:
zip
in interfaceApplicative<A,LambdaIterable<?>>
- Specified by:
zip
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
zip
in 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 alazy
instance 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:
lazyZip
in interfaceApplicative<A,LambdaIterable<?>>
- Specified by:
lazyZip
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
lazyZip
in 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 thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.- Specified by:
discardL
in interfaceApplicative<A,LambdaIterable<?>>
- Specified by:
discardL
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
discardL
in 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 thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.- Specified by:
discardR
in interfaceApplicative<A,LambdaIterable<?>>
- Specified by:
discardR
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
discardR
in 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:
flatMap
in interfaceMonad<A,LambdaIterable<?>>
- Specified by:
flatMap
in 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 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,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)
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,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:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
wrap
public static <A> LambdaIterable<A> wrap(java.lang.Iterable<? extends A> as)
Wrap anIterable
in 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 emptyLambdaIterable
by wrappingCollections.emptyList()
.- Type Parameters:
A
- the Iterable element type- Returns:
- an empty
LambdaIterable
-
pureLambdaIterable
public static Pure<LambdaIterable<?>> pureLambdaIterable()
The canonicalPure
instance forLambdaIterable
.- Returns:
- the
Pure
instance
-
-