Class Trampoline<A>
java.lang.Object
fj.control.Trampoline<A>
- Direct Known Subclasses:
Trampoline.Codense, Trampoline.Normal
A Trampoline is a potentially branching computation that can be stepped through and executed in constant stack.
It represents suspendable coroutines with subroutine calls, reified as a data structure.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static classprivate static final classprivate static final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <B> Trampoline<B> apply(Trampoline<F<A, B>> lf) Performs function application within a Trampoline (applicative functor pattern).final <B,C> Trampoline <C> bind(Trampoline<B> lb, F<A, F<B, C>> f) Binds the given function across the result of this Trampoline and the given Trampoline.abstract <B> Trampoline<B> bind(F<A, Trampoline<B>> f) Binds the given continuation to the result of this trampoline.static <A,B> F <F<A, Trampoline<B>>, F<Trampoline<A>, Trampoline<B>>> bind_()private static <A,B> Trampoline.Codense <B> codense(Trampoline.Normal<A> a, F<A, Trampoline<B>> k) protected abstract <R> Rfold(F<Trampoline.Normal<A>, R> n, F<Trampoline.Codense<A>, R> gs) static <A,B, C> F <Trampoline<A>, F<Trampoline<B>, Trampoline<C>>> Promotes the given function of arity-2 to a function on Trampolines.final <B> Trampoline<B> Maps the given function across the result of this trampoline.static <A,B> F <F<A, B>, F<Trampoline<A>, Trampoline<B>>> map_()static <A> F<A, Trampoline<A>> pure()static <A> Trampoline<A> pure(A a) Constructs a pure computation that results in the given value.abstract Either<P1<Trampoline<A>>, A> resume()Runs a single step of this computation.static <A> F<Trampoline<A>, Either<P1<Trampoline<A>>, A>> resume_()final Arun()Runs this computation all the way to the end, in constant stack.static <A> Trampoline<A> suspend(F0<Trampoline<A>> a) Suspends the given computation in a thunk.static <A> Trampoline<A> suspend(P1<Trampoline<A>> a) Suspends the given computation in a thunk.static <A> F<P1<Trampoline<A>>, Trampoline<A>> suspend_()final <B,C> Trampoline <C> zipWith(Trampoline<B> b, F2<A, B, C> f) Combines two trampolines so they run cooperatively.
-
Constructor Details
-
Trampoline
public Trampoline()
-
-
Method Details
-
codense
-
pure
- Returns:
- The first-class version of
pure.
-
pure
Constructs a pure computation that results in the given value.- Parameters:
a- The value of the result.- Returns:
- A trampoline that results in the given value.
-
suspend
Suspends the given computation in a thunk.- Parameters:
a- A trampoline suspended in a thunk.- Returns:
- A trampoline whose next step runs the given thunk.
-
suspend
Suspends the given computation in a thunk.- Parameters:
a- A trampoline suspended in a thunk.- Returns:
- A trampoline whose next step runs the given thunk.
-
suspend_
- Returns:
- The first-class version of
suspend.
-
fold
-
bind
Binds the given continuation to the result of this trampoline.- Parameters:
f- A function that constructs a trampoline from the result of this trampoline.- Returns:
- A new trampoline that runs this trampoline, then continues with the given function.
-
map
Maps the given function across the result of this trampoline.- Parameters:
f- A function that gets applied to the result of this trampoline.- Returns:
- A new trampoline that runs this trampoline, then applies the given function to the result.
-
bind_
- Returns:
- The first-class version of
bind.
-
map_
- Returns:
- The first-class version of
map.
-
resume_
- Returns:
- The first-class version of
resume.
-
resume
Runs a single step of this computation.- Returns:
- The next step of this compuation.
-
run
Runs this computation all the way to the end, in constant stack.- Returns:
- The end result of this computation.
-
apply
Performs function application within a Trampoline (applicative functor pattern).- Parameters:
lf- A Trampoline resulting in the function to apply.- Returns:
- A new Trampoline after applying the given function through this Trampoline.
-
bind
Binds the given function across the result of this Trampoline and the given Trampoline.- Parameters:
lb- A given Trampoline to bind the given function with.f- The function to combine the results of this Trampoline and the given Trampoline.- Returns:
- A new Trampoline combining the results of the two trampolines with the given function.
-
liftM2
Promotes the given function of arity-2 to a function on Trampolines.- Parameters:
f- The function to promote to a function on Trampolines.- Returns:
- The given function, promoted to operate on Trampolines.
-
zipWith
Combines two trampolines so they run cooperatively. The results are combined with the given function.- Parameters:
b- Another trampoline to combine with this trampoline.f- A function to combine the results of the two trampolines.- Returns:
- A new trampoline that runs this trampoline and the given trampoline simultaneously.
-