A
- The output Iterable element typeB
- The unfolding function input typepublic final class Unfoldr<A,B> extends Object implements Fn2<Fn1<? super B,Maybe<Tuple2<A,B>>>,B,Iterable<A>>
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);
Modifier and Type | Method and Description |
---|---|
Iterable<A> |
checkedApply(Fn1<? super B,Maybe<Tuple2<A,B>>> fn,
B b) |
static <A,B> Unfoldr<A,B> |
unfoldr() |
static <A,B> Fn1<B,Iterable<A>> |
unfoldr(Fn1<? super B,Maybe<Tuple2<A,B>>> fn) |
static <A,B> Iterable<A> |
unfoldr(Fn1<? super B,Maybe<Tuple2<A,B>>> fn,
B b) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
apply, apply, checkedApply, compose, contraMap, curried, curry, diMapL, discardR, flip, fn2, fromBiFunction, toBiFunction, uncurry, widen