Package com.jnape.palatable.lambda.monad
Interface MonadError<E,A,M extends MonadError<E,?,M>>
-
- Type Parameters:
E- the error typeM- theMonadwitnessA- 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 formonadsthat can be interrupted with some type of error. The type of error is fully dictated by the instance ofMonadErrorand is not necessarily analogous to Javaexceptionsor evenThrowable. For instance,IOcan be thrown anyThrowable, where asEithercan only be "thrown" a value of itslefttype.
-
-
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 thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.default <B> MonadError<E,A,M>discardR(Applicative<B,M> appB)Sequence both thisApplicativeandappB, discardingappB'sresult 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 alazyinstance 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 valuebinto this applicative functor.MonadError<E,A,M>throwError(E e)Throw an error value of typeEinto 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 typeEinto 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 valuebinto 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 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.
-
discardL
default <B> MonadError<E,B,M> discardL(Applicative<B,M> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult 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 thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.
-
-