Package com.jnape.palatable.lambda.monad
Interface MonadError<E,A,M extends MonadError<E,?,M>>
-
- Type Parameters:
E
- the error typeM
- theMonad
witnessA
- the carrier
- All Superinterfaces:
Applicative<A,M>
,Functor<A,M>
,Monad<A,M>
- All Known Implementing Classes:
Either
,Either.Left
,Either.Right
,EitherT
,IO
,IO.Compose
,Maybe
,Maybe.Just
,Maybe.Nothing
,MaybeT
,Try
,Try.Failure
,Try.Success
public interface MonadError<E,A,M extends MonadError<E,?,M>> extends Monad<A,M>
An interface formonads
that can be interrupted with some type of error. The type of error is fully dictated by the instance ofMonadError
and is not necessarily analogous to Javaexceptions
or evenThrowable
. For instance,IO
can be thrown anyThrowable
, where asEither
can only be "thrown" a value of itsleft
type.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description MonadError<E,A,M>
catchError(Fn1<? super E,? extends Monad<A,M>> recoveryFn)
default <B> MonadError<E,B,M>
discardL(Applicative<B,M> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.default <B> MonadError<E,A,M>
discardR(Applicative<B,M> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.<B> MonadError<E,B,M>
flatMap(Fn1<? super A,? extends Monad<B,M>> f)
Chain dependent computations that may continue or short-circuit based on previous results.default <B> MonadError<E,B,M>
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.default <B> Lazy<? extends MonadError<E,B,M>>
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,M>> lazyAppFn)
Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.<B> MonadError<E,B,M>
pure(B b)
Lift the valueb
into this applicative functor.MonadError<E,A,M>
throwError(E e)
Throw an error value of typeE
into themonad
.default <B> MonadError<E,B,M>
zip(Applicative<Fn1<? super A,? extends B>,M> 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
-
throwError
MonadError<E,A,M> throwError(E e)
Throw an error value of typeE
into themonad
.- Parameters:
e
- the error type- Returns:
- the
monad
-
catchError
MonadError<E,A,M> catchError(Fn1<? super E,? extends Monad<A,M>> recoveryFn)
- Parameters:
recoveryFn
- the catch function- Returns:
- the recovered
Monad
-
flatMap
<B> MonadError<E,B,M> flatMap(Fn1<? super A,? extends Monad<B,M>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
-
pure
<B> MonadError<E,B,M> pure(B b)
Lift the valueb
into this applicative functor.
-
fmap
default <B> MonadError<E,B,M> fmap(Fn1<? super A,? extends B> 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.
-
zip
default <B> MonadError<E,B,M> zip(Applicative<Fn1<? super A,? extends B>,M> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
lazyZip
default <B> Lazy<? extends MonadError<E,B,M>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,M>> 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.
-
discardL
default <B> MonadError<E,B,M> discardL(Applicative<B,M> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.
-
discardR
default <B> MonadError<E,A,M> discardR(Applicative<B,M> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.
-
-