A
- the input typeB
- the output typepublic final class LazyRec<A,B> extends Object implements Fn2<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,A,Lazy<B>>
Fn2
that receives a recursive function and an input and yields a lazy
result, and an
input, produce a lazy
result that, when forced, will recursively invoke the function until it terminates
in a stack-safe way.
Example:
Lazy<BigInteger> lazyFactorial = lazyRec((fact, x) -> x.equals(ONE)
? lazy(x)
: fact.apply(x.subtract(ONE)).fmap(y -> y.multiply(x)),
BigInteger.valueOf(50_000));
BigInteger value = lazyFactorial.value(); // 3.34732050959714483691547609407148647791277322381045 x 10^213236
Modifier and Type | Method and Description |
---|---|
Lazy<B> |
checkedApply(Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>> fn,
A a) |
static <A,B> LazyRec<A,B> |
lazyRec() |
static <A,B> Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>> |
lazyRec(Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>> fn) |
static <A,B> Lazy<B> |
lazyRec(Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>> fn,
A a) |
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
public Lazy<B> checkedApply(Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>> fn, A a)
public static <A,B> LazyRec<A,B> lazyRec()
public static <A,B> Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>> lazyRec(Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>> fn)