Class LazyRec<A,B>
- java.lang.Object
-
- com.jnape.palatable.lambda.functions.builtin.fn2.LazyRec<A,B>
-
- Type Parameters:
A- the input typeB- the output type
- All Implemented Interfaces:
Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Fn1<A,Lazy<B>>>,Fn2<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,A,Lazy<B>>,Applicative<Fn1<A,Lazy<B>>,Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,?>>,Cartesian<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Fn1<A,Lazy<B>>,Fn1<?,?>>,Cocartesian<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Fn1<A,Lazy<B>>,Fn1<?,?>>,Contravariant<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Profunctor<?,Fn1<A,Lazy<B>>,Fn1<?,?>>>,Functor<Fn1<A,Lazy<B>>,Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,?>>,Profunctor<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Fn1<A,Lazy<B>>,Fn1<?,?>>,Monad<Fn1<A,Lazy<B>>,Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,?>>,MonadReader<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Fn1<A,Lazy<B>>,Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,?>>,MonadRec<Fn1<A,Lazy<B>>,Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,?>>,MonadWriter<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,Fn1<A,Lazy<B>>,Fn1<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,?>>
public final class LazyRec<A,B> extends java.lang.Object implements Fn2<Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>>,A,Lazy<B>>
Given aFn2that receives a recursive function and an input and yields alazyresult, and an input, produce alazyresult 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
-
-
Constructor Summary
Constructors Modifier Constructor Description privateLazyRec()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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)-
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 LazyRec<?,?> INSTANCE
-
-
Method Detail
-
checkedApply
public Lazy<B> checkedApply(Fn2<Kleisli<? super A,? extends B,Lazy<?>,Lazy<B>>,A,Lazy<B>> fn, A a)
-
lazyRec
public static <A,B> LazyRec<A,B> lazyRec()
-
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)
-
-