Class EitherT<M extends MonadRec<?,M>,L,R>
- java.lang.Object
-
- com.jnape.palatable.lambda.monad.transformer.builtin.EitherT<M,L,R>
-
- Type Parameters:
M- the outerstack-safe monadL- the left typeR- the right type
- All Implemented Interfaces:
Applicative<R,EitherT<M,L,?>>,Bifunctor<L,R,EitherT<M,?,?>>,BoundedBifunctor<L,R,java.lang.Object,java.lang.Object,EitherT<M,?,?>>,Functor<R,EitherT<M,L,?>>,Monad<R,EitherT<M,L,?>>,MonadBase<M,R,EitherT<?,L,?>>,MonadError<L,R,EitherT<M,L,?>>,MonadRec<R,EitherT<M,L,?>>,MonadT<M,R,EitherT<M,L,?>,EitherT<?,L,?>>
public final class EitherT<M extends MonadRec<?,M>,L,R> extends java.lang.Object implements Bifunctor<L,R,EitherT<M,?,?>>, MonadT<M,R,EitherT<M,L,?>,EitherT<?,L,?>>, MonadError<L,R,EitherT<M,L,?>>
Amonad transformerforEither.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <L2,R2>
EitherT<M,L2,R2>biMap(Fn1<? super L,? extends L2> lFn, Fn1<? super R,? extends R2> rFn)Dually map covariantly over both the left and right parameters.<L2> EitherT<M,L2,R>biMapL(Fn1<? super L,? extends L2> fn)Covariantly map over the left parameter.<R2> EitherT<M,L,R2>biMapR(Fn1<? super R,? extends R2> fn)Covariantly map over the right parameter.EitherT<M,L,R>catchError(Fn1<? super L,? extends Monad<R,EitherT<M,L,?>>> recoveryFn)<R2> EitherT<M,L,R2>discardL(Applicative<R2,EitherT<M,L,?>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.<B> EitherT<M,L,R>discardR(Applicative<B,EitherT<M,L,?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.static <M extends MonadRec<?,M>,L,R>
EitherT<M,L,R>eitherT(MonadRec<Either<L,R>,M> melr)booleanequals(java.lang.Object other)<R2> EitherT<M,L,R2>flatMap(Fn1<? super R,? extends Monad<R2,EitherT<M,L,?>>> f)Chain dependent computations that may continue or short-circuit based on previous results.<R2> EitherT<M,L,R2>fmap(Fn1<? super R,? extends R2> fn)Covariantly transmute this functor's parameter using the given mapping function.inthashCode()<R2> Lazy<EitherT<M,L,R2>>lazyZip(Lazy<? extends Applicative<Fn1<? super R,? extends R2>,EitherT<M,L,?>>> lazyAppFn)Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.<R2,N extends MonadRec<?,N>>
EitherT<N,L,R2>lift(MonadRec<R2,N> mb)static <L> Lift<EitherT<?,L,?>>liftEitherT()<R2> EitherT<M,L,R2>pure(R2 r2)Lift the valuebinto this applicative functor.static <M extends MonadRec<?,M>,L>
Pure<EitherT<M,L,?>>pureEitherT(Pure<M> pureM)<MELR extends MonadRec<Either<L,R>,M>>
MELRrunEitherT()Recover the full structure of the embeddedMonad.EitherT<M,L,R>throwError(L l)Throw an error value of typeEinto themonad.java.lang.StringtoString()<R2> EitherT<M,L,R2>trampolineM(Fn1<? super R,? extends MonadRec<RecursiveResult<R,R2>,EitherT<M,L,?>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<R2> EitherT<M,L,R2>zip(Applicative<Fn1<? super R,? extends R2>,EitherT<M,L,?>> appFn)Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
-
-
Method Detail
-
runEitherT
public <MELR extends MonadRec<Either<L,R>,M>> MELR runEitherT()
Recover the full structure of the embeddedMonad.- Type Parameters:
MELR- the witnessed target type- Returns:
- the embedded
Monad
-
lift
public <R2,N extends MonadRec<?,N>> EitherT<N,L,R2> lift(MonadRec<R2,N> mb)
- Specified by:
liftin interfaceMonadBase<M extends MonadRec<?,M>,L,R>- Specified by:
liftin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- theMonadReccarrier typeN- the argumentMonadRecwitness- Parameters:
mb- the argumentMonadRec- Returns:
- the new
MonadBase
-
flatMap
public <R2> EitherT<M,L,R2> flatMap(Fn1<? super R,? extends Monad<R2,EitherT<M,L,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMapin interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
flatMapin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
flatMapin interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
flatMapin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- the resulting monad parameter type- Parameters:
f- the dependent computation over A- Returns:
- the new monad instance
-
pure
public <R2> EitherT<M,L,R2> pure(R2 r2)
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<M extends MonadRec<?,M>,L>- Specified by:
purein interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
purein interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
purein interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
purein interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- the type of the returned applicative's parameter- Parameters:
r2- the value- Returns:
- an instance of this applicative over b
-
fmap
public <R2> EitherT<M,L,R2> fmap(Fn1<? super R,? extends R2> fn)
Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.- Specified by:
fmapin interfaceApplicative<M extends MonadRec<?,M>,L>- Specified by:
fmapin interfaceFunctor<M extends MonadRec<?,M>,L>- Specified by:
fmapin interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
fmapin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
fmapin interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
fmapin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
zip
public <R2> EitherT<M,L,R2> zip(Applicative<Fn1<? super R,? extends R2>,EitherT<M,L,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.- Specified by:
zipin interfaceApplicative<M extends MonadRec<?,M>,L>- Specified by:
zipin interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
zipin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
zipin interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
zipin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <R2> Lazy<EitherT<M,L,R2>> lazyZip(Lazy<? extends Applicative<Fn1<? super R,? extends R2>,EitherT<M,L,?>>> lazyAppFn)
Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. This is useful for applicatives that support lazy evaluation and early termination.- Specified by:
lazyZipin interfaceApplicative<M extends MonadRec<?,M>,L>- Specified by:
lazyZipin interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
lazyZipin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
lazyZipin interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
lazyZipin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe,Either
-
discardL
public <R2> EitherT<M,L,R2> discardL(Applicative<R2,EitherT<M,L,?>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<M extends MonadRec<?,M>,L>- Specified by:
discardLin interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
discardLin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
discardLin interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
discardLin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
R2- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
public <B> EitherT<M,L,R> discardR(Applicative<B,EitherT<M,L,?>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<M extends MonadRec<?,M>,L>- Specified by:
discardRin interfaceMonad<M extends MonadRec<?,M>,L>- Specified by:
discardRin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Specified by:
discardRin interfaceMonadRec<M extends MonadRec<?,M>,L>- Specified by:
discardRin interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>- Type Parameters:
B- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-
throwError
public EitherT<M,L,R> throwError(L l)
Throw an error value of typeEinto themonad.- Specified by:
throwErrorin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Parameters:
l- the error type- Returns:
- the
monad
-
catchError
public EitherT<M,L,R> catchError(Fn1<? super L,? extends Monad<R,EitherT<M,L,?>>> recoveryFn)
- Specified by:
catchErrorin interfaceMonadError<M extends MonadRec<?,M>,L,R>- Parameters:
recoveryFn- the catch function- Returns:
- the recovered
Monad
-
trampolineM
public <R2> EitherT<M,L,R2> trampolineM(Fn1<? super R,? extends MonadRec<RecursiveResult<R,R2>,EitherT<M,L,?>>> fn)
Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.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.
- Specified by:
trampolineMin interfaceMonadRec<M extends MonadRec<?,M>,L>- Type Parameters:
R2- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
for a basic implementation,for a implementation,for an implementation leveraging an already stack-safe,for a implementation
-
biMap
public <L2,R2> EitherT<M,L2,R2> biMap(Fn1<? super L,? extends L2> lFn, Fn1<? super R,? extends R2> rFn)
Dually map covariantly over both the left and right parameters. This is isomorphic tobiMapL(lFn).biMapR(rFn).- Specified by:
biMapin interfaceBifunctor<M extends MonadRec<?,M>,L,R>- Specified by:
biMapin interfaceBoundedBifunctor<L,R,java.lang.Object,java.lang.Object,EitherT<M extends MonadRec<?,M>,?,?>>- Type Parameters:
L2- the new left parameter typeR2- the new right parameter type- Parameters:
lFn- the left parameter mapping functionrFn- the right parameter mapping function- Returns:
- a bifunctor over C (the new left parameter type) and D (the new right parameter type)
-
biMapL
public <L2> EitherT<M,L2,R> biMapL(Fn1<? super L,? extends L2> fn)
Covariantly map over the left parameter.- Specified by:
biMapLin interfaceBifunctor<M extends MonadRec<?,M>,L,R>- Specified by:
biMapLin interfaceBoundedBifunctor<L,R,java.lang.Object,java.lang.Object,EitherT<M extends MonadRec<?,M>,?,?>>- Type Parameters:
L2- the new left parameter type- Parameters:
fn- the mapping function- Returns:
- a bifunctor over C (the new left parameter) and B (the same right parameter)
-
biMapR
public <R2> EitherT<M,L,R2> biMapR(Fn1<? super R,? extends R2> fn)
Covariantly map over the right parameter. For all bifunctors that are also functors, it should hold thatbiMapR(f) == fmap(f).- Specified by:
biMapRin interfaceBifunctor<M extends MonadRec<?,M>,L,R>- Specified by:
biMapRin interfaceBoundedBifunctor<L,R,java.lang.Object,java.lang.Object,EitherT<M extends MonadRec<?,M>,?,?>>- Type Parameters:
R2- the new right parameter type- Parameters:
fn- the mapping function- Returns:
- a bifunctor over A (the same left parameter) and C (the new right parameter)
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
eitherT
public static <M extends MonadRec<?,M>,L,R> EitherT<M,L,R> eitherT(MonadRec<Either<L,R>,M> melr)
-
pureEitherT
public static <M extends MonadRec<?,M>,L> Pure<EitherT<M,L,?>> pureEitherT(Pure<M> pureM)
-
-