Package com.jnape.palatable.lambda.monad
Interface MonadError<E,A,M extends MonadError<E,?,M>>
- Type Parameters:
E
- the error typeA
- the carrierM
- theMonad
witness
- 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
An interface for
monads
that can be interrupted with some type of error. The type of error is fully
dictated by the instance of MonadError
and is not necessarily analogous to Java exceptions
or even Throwable
. For instance, IO
can be thrown any Throwable
, where as Either
can
only be "thrown" a value of its left
type.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionMonadError
<E, A, M> 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> Chain dependent computations that may continue or short-circuit based on previous results.default <B> MonadError
<E, B, M> Covariantly transmute this functor's parameter using the given mapping function.default <B> Lazy
<? extends MonadError<E, B, M>> 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 Details
-
throwError
Throw an error value of typeE
into themonad
.- Parameters:
e
- the error type- Returns:
- the
monad
-
catchError
- Parameters:
recoveryFn
- the catch function- Returns:
- the recovered
Monad
-
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
pure
Lift the valueb
into this applicative functor. -
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. -
zip
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, lazyZipM>> (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
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects. -
discardR
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.
-