A
- the recursive function's input typeB
- the recursive function's output typepublic abstract class RecursiveResult<A,B> extends Object implements CoProduct2<A,B,RecursiveResult<A,B>>, Bifunctor<A,B,RecursiveResult<?,?>>, MonadRec<B,RecursiveResult<A,?>>, Traversable<B,RecursiveResult<A,?>>
CoProduct2
representing the possible results of a primitive recursive function.
Used by Trampoline
to cheat around CoProduct2.match(com.jnape.palatable.lambda.functions.Fn1<? super A, ? extends R>, com.jnape.palatable.lambda.functions.Fn1<? super B, ? extends R>)
and quickly unpack values via
instanceof
checks to package private inner subtypes.Trampoline
Modifier and Type | Method and Description |
---|---|
<C,D> RecursiveResult<C,D> |
biMap(Fn1<? super A,? extends C> lFn,
Fn1<? super B,? extends D> rFn)
Dually map covariantly over both the left and right parameters.
|
<C> RecursiveResult<C,B> |
biMapL(Fn1<? super A,? extends C> fn)
Covariantly map over the left parameter.
|
<C> RecursiveResult<A,C> |
biMapR(Fn1<? super B,? extends C> fn)
Covariantly map over the right parameter.
|
<C> RecursiveResult<A,C> |
discardL(Applicative<C,RecursiveResult<A,?>> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
<C> RecursiveResult<A,B> |
discardR(Applicative<C,RecursiveResult<A,?>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
<C> RecursiveResult<A,C> |
flatMap(Fn1<? super B,? extends Monad<C,RecursiveResult<A,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
|
<C> RecursiveResult<A,C> |
fmap(Fn1<? super B,? extends C> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
RecursiveResult<B,A> |
invert()
Swap the type parameters.
|
<C> RecursiveResult<A,C> |
pure(C c)
Lift the value
b into this applicative functor. |
static <A> Pure<RecursiveResult<A,?>> |
pureRecursiveResult()
The canonical
Pure instance for RecursiveResult . |
static <A,B> RecursiveResult<A,B> |
recurse(A a)
Static factory method for creating a "recurse" value.
|
static <A,B> RecursiveResult<A,B> |
terminate(B b)
Static factory method for creating a "terminate" value.
|
<C> RecursiveResult<A,C> |
trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,RecursiveResult<A,?>>> fn)
Given some operation yielding a
RecursiveResult inside this MonadRec , internally trampoline the
operation until it yields a termination instruction. |
<C,App extends Applicative<?,App>,TravB extends Traversable<C,RecursiveResult<A,?>>,AppTrav extends Applicative<TravB,App>> |
traverse(Fn1<? super B,? extends Applicative<C,App>> fn,
Fn1<? super TravB,? extends AppTrav> pure)
Apply
fn to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function. |
<C> RecursiveResult<A,C> |
zip(Applicative<Fn1<? super B,? extends C>,RecursiveResult<A,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using
whatever application semantics the current applicative supports.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public RecursiveResult<B,A> invert()
invert
in interface CoProduct2<A,B,RecursiveResult<A,B>>
public <C> RecursiveResult<C,B> biMapL(Fn1<? super A,? extends C> fn)
biMapL
in interface Bifunctor<A,B,RecursiveResult<?,?>>
biMapL
in interface BoundedBifunctor<A,B,Object,Object,RecursiveResult<?,?>>
C
- the new left parameter typefn
- the mapping functionpublic <C> RecursiveResult<A,C> biMapR(Fn1<? super B,? extends C> fn)
biMapR(f) == fmap(f)
.biMapR
in interface Bifunctor<A,B,RecursiveResult<?,?>>
biMapR
in interface BoundedBifunctor<A,B,Object,Object,RecursiveResult<?,?>>
C
- the new right parameter typefn
- the mapping functionpublic <C,D> RecursiveResult<C,D> biMap(Fn1<? super A,? extends C> lFn, Fn1<? super B,? extends D> rFn)
biMapL(lFn).biMapR(rFn)
.biMap
in interface Bifunctor<A,B,RecursiveResult<?,?>>
biMap
in interface BoundedBifunctor<A,B,Object,Object,RecursiveResult<?,?>>
C
- the new left parameter typeD
- the new right parameter typelFn
- the left parameter mapping functionrFn
- the right parameter mapping functionpublic <C> RecursiveResult<A,C> flatMap(Fn1<? super B,? extends Monad<C,RecursiveResult<A,?>>> f)
flatMap
in interface Monad<B,RecursiveResult<A,?>>
flatMap
in interface MonadRec<B,RecursiveResult<A,?>>
C
- the resulting monad parameter typef
- the dependent computation over Apublic <C> RecursiveResult<A,C> pure(C c)
b
into this applicative functor.pure
in interface Applicative<B,RecursiveResult<A,?>>
pure
in interface Monad<B,RecursiveResult<A,?>>
pure
in interface MonadRec<B,RecursiveResult<A,?>>
C
- the type of the returned applicative's parameterc
- the valuepublic <C> RecursiveResult<A,C> fmap(Fn1<? super B,? extends C> fn)
fmap
in interface Applicative<B,RecursiveResult<A,?>>
fmap
in interface Functor<B,RecursiveResult<A,?>>
fmap
in interface Monad<B,RecursiveResult<A,?>>
fmap
in interface MonadRec<B,RecursiveResult<A,?>>
fmap
in interface Traversable<B,RecursiveResult<A,?>>
C
- the new parameter typefn
- the mapping functionpublic <C> RecursiveResult<A,C> zip(Applicative<Fn1<? super B,? extends C>,RecursiveResult<A,?>> appFn)
zip
in interface Applicative<B,RecursiveResult<A,?>>
zip
in interface Monad<B,RecursiveResult<A,?>>
zip
in interface MonadRec<B,RecursiveResult<A,?>>
C
- the resulting applicative parameter typeappFn
- the other applicative instancepublic <C> RecursiveResult<A,C> discardL(Applicative<C,RecursiveResult<A,?>> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.discardL
in interface Applicative<B,RecursiveResult<A,?>>
discardL
in interface Monad<B,RecursiveResult<A,?>>
discardL
in interface MonadRec<B,RecursiveResult<A,?>>
C
- the type of the returned Applicative's parameterappB
- the other Applicativepublic <C> RecursiveResult<A,B> discardR(Applicative<C,RecursiveResult<A,?>> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.discardR
in interface Applicative<B,RecursiveResult<A,?>>
discardR
in interface Monad<B,RecursiveResult<A,?>>
discardR
in interface MonadRec<B,RecursiveResult<A,?>>
C
- the type of appB's parameterappB
- the other Applicativepublic <C> RecursiveResult<A,C> trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,RecursiveResult<A,?>>> fn)
RecursiveResult
inside this MonadRec
, internally trampoline the
operation until it yields a termination
instruction.
Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
trampolineM
in interface MonadRec<B,RecursiveResult<A,?>>
C
- the ultimate resulting carrier typefn
- the function to internally trampolineMonadRec
for a basic implementation
,
for a {@link CoProduct2 coproduct} implementation
,
for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}
,
for a {@link MonadT monad transformer} implementation
public <C,App extends Applicative<?,App>,TravB extends Traversable<C,RecursiveResult<A,?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super B,? extends Applicative<C,App>> fn, Fn1<? super TravB,? extends AppTrav> pure)
fn
to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function.traverse
in interface Traversable<B,RecursiveResult<A,?>>
C
- the resulting element typeApp
- the result applicative typeTravB
- this Traversable instance over BAppTrav
- the full inferred resulting type from the traversalfn
- the function to applypure
- the applicative pure functionpublic static <A,B> RecursiveResult<A,B> recurse(A a)
A
- the recurse typeB
- the terminate typea
- the valueRecursiveResult
public static <A,B> RecursiveResult<A,B> terminate(B b)
A
- the recurse typeB
- the terminate typeb
- the valueRecursiveResult
public static <A> Pure<RecursiveResult<A,?>> pureRecursiveResult()
Pure
instance for RecursiveResult
.A
- the recursive function's input typePure
instance