Interface MonadT<M extends MonadRec<?,M>,A,MT extends MonadT<M,?,MT,T>,T extends MonadT<?,?,?,T>>
- Type Parameters:
M- the argumentmonadA- the carrier typeMT- theMonadwitnessT- theMonadTwitness
- All Superinterfaces:
Applicative<A,,MT> Functor<A,,MT> Monad<A,,MT> MonadBase<M,,A, T> MonadRec<A,MT>
- All Known Implementing Classes:
EitherT,IdentityT,IterateT,LazyT,MaybeT,ReaderT,SafeT,StateT,WriterT
Monad transformer, exposing the argument Monad as a type parameter.
While any two functors and any two applicatives can be composed in general, the
same is not true in general of any two monads. However, there exist monads that do
compose, in general, with any other Monad. When this is the case, the combination of these
monads with any other Monad can offer composed implementations of pure and
flatMap for free, simply by relying on the other monad's implementation of
both, as well as their own privileged knowledge about how to merge the nested flatMap
call. This can be thought of as "gluing" together two monads, allowing easier access to their values,
as well as, in some cases, providing universally correct constructions of the composed short-circuiting algorithms.
The term "monad transformer" describes this particular encoding of monadic composition, and tends to be
named in terms of Monad for which privileged knowledge must be known in order to eliminate during
flatmapping.
For more information, read more about monad transformers.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondiscardL(Applicative<B, MT> appB) Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<B, MT> appB) Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.pure(B b) Lift the valuebinto this applicative functor.zip(Applicative<Fn1<? super A, ? extends B>, MT> appFn) Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.Methods inherited from interface com.jnape.palatable.lambda.monad.MonadRec
trampolineM
-
Method Details
-
lift
-
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
pure
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<M extends MonadRec<?,M>, A> - Specified by:
purein interfaceMonad<M extends MonadRec<?,M>, A> - Specified by:
purein interfaceMonadRec<M extends MonadRec<?,M>, A> - Type Parameters:
B- the type of the returned applicative's parameter- Parameters:
b- 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:
fmapin interfaceApplicative<M extends MonadRec<?,M>, A> - Specified by:
fmapin interfaceFunctor<M extends MonadRec<?,M>, A> - Specified by:
fmapin interfaceMonad<M extends MonadRec<?,M>, A> - Specified by:
fmapin interfaceMonadRec<M extends MonadRec<?,M>, A> - Type Parameters:
B- 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:
zipin interfaceApplicative<M extends MonadRec<?,M>, A> - Specified by:
zipin interfaceMonad<M extends MonadRec<?,M>, A> - Specified by:
zipin interfaceMonadRec<M extends MonadRec<?,M>, A> - Type Parameters:
B- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
default <B> Lazy<? extends MonadT<M,B, lazyZipMT, T>> (Lazy<? extends Applicative<Fn1<? super A, ? extends B>, MT>> 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.- Specified by:
lazyZipin interfaceApplicative<M extends MonadRec<?,M>, A> - Specified by:
lazyZipin interfaceMonad<M extends MonadRec<?,M>, A> - Specified by:
lazyZipin interfaceMonadRec<M extends MonadRec<?,M>, A> - Type Parameters:
B- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
-
discardL
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<M extends MonadRec<?,M>, A> - Specified by:
discardLin interfaceMonad<M extends MonadRec<?,M>, A> - Specified by:
discardLin interfaceMonadRec<M extends MonadRec<?,M>, A> - Type Parameters:
B- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<M extends MonadRec<?,M>, A> - Specified by:
discardRin interfaceMonad<M extends MonadRec<?,M>, A> - Specified by:
discardRin interfaceMonadRec<M extends MonadRec<?,M>, A> - Type Parameters:
B- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-