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,java.lang.Iterable<A>>>
,Fn2<Fn1<? super B,Maybe<Tuple2<A,B>>>,B,java.lang.Iterable<A>>
,Applicative<Fn1<B,java.lang.Iterable<A>>,Fn1<Fn1<? super B,Maybe<Tuple2<A,B>>>,?>>
,Cartesian<Fn1<? super B,Maybe<Tuple2<A,B>>>,Fn1<B,java.lang.Iterable<A>>,Fn1<?,?>>
,Cocartesian<Fn1<? super B,Maybe<Tuple2<A,B>>>,Fn1<B,java.lang.Iterable<A>>,Fn1<?,?>>
,Contravariant<Fn1<? super B,Maybe<Tuple2<A,B>>>,Profunctor<?,Fn1<B,java.lang.Iterable<A>>,Fn1<?,?>>>
,Functor<Fn1<B,java.lang.Iterable<A>>,Fn1<Fn1<? super B,Maybe<Tuple2<A,B>>>,?>>
,Profunctor<Fn1<? super B,Maybe<Tuple2<A,B>>>,Fn1<B,java.lang.Iterable<A>>,Fn1<?,?>>
,Monad<Fn1<B,java.lang.Iterable<A>>,Fn1<Fn1<? super B,Maybe<Tuple2<A,B>>>,?>>
,MonadReader<Fn1<? super B,Maybe<Tuple2<A,B>>>,Fn1<B,java.lang.Iterable<A>>,Fn1<Fn1<? super B,Maybe<Tuple2<A,B>>>,?>>
,MonadRec<Fn1<B,java.lang.Iterable<A>>,Fn1<Fn1<? super B,Maybe<Tuple2<A,B>>>,?>>
,MonadWriter<Fn1<? super B,Maybe<Tuple2<A,B>>>,Fn1<B,java.lang.Iterable<A>>,Fn1<Fn1<? super B,Maybe<Tuple2<A,B>>>,?>>
public final class Unfoldr<A,B> extends java.lang.Object implements Fn2<Fn1<? super B,Maybe<Tuple2<A,B>>>,B,java.lang.Iterable<A>>
Given an initial seed value and a function that takes the seed type and produces an
, where the tuple's first slot represents the nextMaybe
<Tuple2
<X, Seed>>Iterable
element, and the second slot represents the next input to the unfolding function, unfold anIterable
ofX
s. ReturningMaybe.nothing()
from the unfolding function is a signal that theIterable
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);
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Unfoldr()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.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,java.lang.Iterable<A>>unfoldr(Fn1<? super B,Maybe<Tuple2<A,B>>> fn)
static <A,B>
java.lang.Iterable<A>unfoldr(Fn1<? super B,Maybe<Tuple2<A,B>>> fn, B b)
-
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
-
-
-
-
Field Detail
-
INSTANCE
private static final Unfoldr<?,?> INSTANCE
-
-