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 monad
L
- 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 transformer
forEither
.
-
-
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 thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<B> EitherT<M,L,R>
discardR(Applicative<B,EitherT<M,L,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.static <M extends MonadRec<?,M>,L,R>
EitherT<M,L,R>eitherT(MonadRec<Either<L,R>,M> melr)
boolean
equals(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.int
hashCode()
<R2> Lazy<EitherT<M,L,R2>>
lazyZip(Lazy<? extends Applicative<Fn1<? super R,? extends R2>,EitherT<M,L,?>>> lazyAppFn)
Given alazy
instance 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 valueb
into 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 typeE
into themonad
.java.lang.String
toString()
<R2> EitherT<M,L,R2>
trampolineM(Fn1<? super R,? extends MonadRec<RecursiveResult<R,R2>,EitherT<M,L,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<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:
lift
in interfaceMonadBase<M extends MonadRec<?,M>,L,R>
- Specified by:
lift
in interfaceMonadT<M extends MonadRec<?,M>,R,EitherT<M extends MonadRec<?,M>,L,?>,EitherT<?,L,?>>
- Type Parameters:
R2
- theMonadRec
carrier typeN
- the argumentMonadRec
witness- 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:
flatMap
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
flatMap
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
flatMap
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
flatMap
in 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 valueb
into this applicative functor.- Specified by:
pure
in interfaceApplicative<M extends MonadRec<?,M>,L>
- Specified by:
pure
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
pure
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
pure
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
pure
in 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:
fmap
in interfaceApplicative<M extends MonadRec<?,M>,L>
- Specified by:
fmap
in interfaceFunctor<M extends MonadRec<?,M>,L>
- Specified by:
fmap
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
fmap
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
fmap
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
fmap
in 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:
zip
in interfaceApplicative<M extends MonadRec<?,M>,L>
- Specified by:
zip
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
zip
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
zip
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
zip
in 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 alazy
instance 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:
lazyZip
in interfaceApplicative<M extends MonadRec<?,M>,L>
- Specified by:
lazyZip
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
lazyZip
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
lazyZip
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
lazyZip
in 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 thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.- Specified by:
discardL
in interfaceApplicative<M extends MonadRec<?,M>,L>
- Specified by:
discardL
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
discardL
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
discardL
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
discardL
in 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 thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.- Specified by:
discardR
in interfaceApplicative<M extends MonadRec<?,M>,L>
- Specified by:
discardR
in interfaceMonad<M extends MonadRec<?,M>,L>
- Specified by:
discardR
in interfaceMonadError<M extends MonadRec<?,M>,L,R>
- Specified by:
discardR
in interfaceMonadRec<M extends MonadRec<?,M>,L>
- Specified by:
discardR
in 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 typeE
into themonad
.- Specified by:
throwError
in 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:
catchError
in 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 aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
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.
- Specified by:
trampolineM
in 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:
biMap
in interfaceBifunctor<M extends MonadRec<?,M>,L,R>
- Specified by:
biMap
in 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:
biMapL
in interfaceBifunctor<M extends MonadRec<?,M>,L,R>
- Specified by:
biMapL
in 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:
biMapR
in interfaceBifunctor<M extends MonadRec<?,M>,L,R>
- Specified by:
biMapR
in 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:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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)
-
-