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, Object, 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 Object
implements Bifunctor<L,R,EitherT<M,?,?>>, MonadT<M,R,EitherT<M,L,?>,EitherT<?,L,?>>, MonadError<L,R,EitherT<M,L,?>>
A
monad transformer
for Either
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDually map covariantly over both the left and right parameters.Covariantly map over the left parameter.Covariantly map over the right parameter.discardL
(Applicative<R2, EitherT<M, L, ?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.discardR
(Applicative<B, EitherT<M, L, ?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.boolean
Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.int
hashCode()
Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.pure
(R2 r2) Lift the valueb
into this applicative functor.pureEitherT
(Pure<M> pureM) Recover the full structure of the embeddedMonad
.throwError
(L l) Throw an error value of typeE
into themonad
.toString()
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.Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
Field Details
-
melr
-
-
Constructor Details
-
EitherT
-
-
Method Details
-
runEitherT
Recover the full structure of the embeddedMonad
.- Type Parameters:
MELR
- the witnessed target type- Returns:
- the embedded
Monad
-
lift
- 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
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
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
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
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, lazyZipR2>> (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:
-
discardL
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
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
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
- 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, trampolineMR2> (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.
-
biMap
public <L2,R2> EitherT<M,L2, biMapR2> (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, Object, 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
Covariantly map over the left parameter.- Specified by:
biMapL
in interfaceBifunctor<M extends MonadRec<?,
M>, L, R> - Specified by:
biMapL
in interfaceBoundedBifunctor<L,
R, Object, 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
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, Object, 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
-
hashCode
public int hashCode() -
toString
-
eitherT
-
pureEitherT
-
liftEitherT
-