A
- the trampolined function's input typeB
- the trampolined function's output typepublic final class Trampoline<A,B> extends Object implements Fn2<Fn1<? super A,? extends RecursiveResult<A,B>>,A,B>
Fn1
<A, CoProduct2
<A, B, ?>>
(analogous to "recurse" and "return"
tail position instructions, respectively), produce a Fn1
<A, B>
that unrolls the original
function by iteratively passing each result that matches the input (A
) back to the original function,
and then terminating on and returning the first output (B
).
This is isomorphic to - though presumably faster than - taking the last element of an Unfoldr
call.
Constructor and Description |
---|
Trampoline() |
Modifier and Type | Method and Description |
---|---|
B |
checkedApply(Fn1<? super A,? extends RecursiveResult<A,B>> fn,
A a) |
static <A,B> Trampoline<A,B> |
trampoline() |
static <A,B> Fn1<A,B> |
trampoline(Fn1<? super A,? extends RecursiveResult<A,B>> fn) |
static <A,B> B |
trampoline(Fn1<? super A,? extends RecursiveResult<A,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 B checkedApply(Fn1<? super A,? extends RecursiveResult<A,B>> fn, A a)
checkedApply
in interface Fn2<Fn1<? super A,? extends RecursiveResult<A,B>>,A,B>
public static <A,B> Trampoline<A,B> trampoline()
public static <A,B> Fn1<A,B> trampoline(Fn1<? super A,? extends RecursiveResult<A,B>> fn)
public static <A,B> B trampoline(Fn1<? super A,? extends RecursiveResult<A,B>> fn, A a)