Class Unfoldr<A,B>
java.lang.Object
com.jnape.palatable.lambda.functions.builtin.fn2.Unfoldr<A,B>
- Type Parameters:
A
- The output Iterable element typeB
- The unfolding function input type
- All Implemented Interfaces:
Fn1<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, Fn1<B, Iterable<A>>> Fn2<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, B, Iterable<A>> Applicative<Fn1<B,
,Iterable<A>>, Fn1<Fn1<? super B, Maybe<Tuple2<A, B>>>, ?>> Cartesian<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, Fn1<B, Iterable<A>>, Fn1<?, ?>> Cocartesian<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, Fn1<B, Iterable<A>>, Fn1<?, ?>> Contravariant<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, Profunctor<?, Fn1<B, Iterable<A>>, Fn1<?, ?>>> Functor<Fn1<B,
,Iterable<A>>, Fn1<Fn1<? super B, Maybe<Tuple2<A, B>>>, ?>> Profunctor<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, Fn1<B, Iterable<A>>, Fn1<?, ?>> Monad<Fn1<B,
,Iterable<A>>, Fn1<Fn1<? super B, Maybe<Tuple2<A, B>>>, ?>> MonadReader<Fn1<? super B,
,Maybe<Tuple2<A, B>>>, Fn1<B, Iterable<A>>, Fn1<Fn1<? super B, Maybe<Tuple2<A, B>>>, ?>> MonadRec<Fn1<B,
,Iterable<A>>, Fn1<Fn1<? super B, Maybe<Tuple2<A, B>>>, ?>> MonadWriter<Fn1<? super B,
Maybe<Tuple2<A, B>>>, Fn1<B, Iterable<A>>, Fn1<Fn1<? super B, Maybe<Tuple2<A, B>>>, ?>>
public final class Unfoldr<A,B>
extends Object
implements Fn2<Fn1<? super B,Maybe<Tuple2<A,B>>>,B,Iterable<A>>
Given an initial seed value and a function that takes the seed type and produces an
Maybe
<Tuple2
<X, Seed>>
, where the tuple's first slot represents the next Iterable
element,
and the second slot represents the next input to the unfolding function, unfold an Iterable
of
X
s. Returning Maybe.nothing()
from the unfolding function is a signal that the Iterable
is fully unfolded.
For more information, read about Anamorphisms.
Example:
Iterable<Integer> zeroThroughTenInclusive = unfoldr(x -> x <= 10
? Maybe.just(tuple(x, x + 1))
: Maybe.nothing(), 0);
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jnape.palatable.lambda.functions.Fn1
andThen, carry, cartesian, censor, choose, cocartesian, diMap, diMapR, discardL, flatMap, fmap, lazyZip, listens, local, pure, self, thunk, toFunction, trampolineM, zip, zip