Interface MonadT<M extends MonadRec<?,M>,A,MT extends MonadT<M,?,MT,T>,T extends MonadT<?,?,?,T>>
-
- Type Parameters:
M
- the argumentmonad
A
- the carrier typeMT
- theMonad
witnessT
- theMonadT
witness
- 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
public interface MonadT<M extends MonadRec<?,M>,A,MT extends MonadT<M,?,MT,T>,T extends MonadT<?,?,?,T>> extends MonadBase<M,A,T>, Monad<A,MT>, MonadRec<A,MT>
The generic type representing aMonad
transformer, exposing the argumentMonad
as a type parameter.While any two
functors
and any twoapplicatives
can be composed in general, the same is not true in general of any twomonads
. However, there existmonads
that do compose, in general, with any otherMonad
. When this is the case, the combination of thesemonads
with any otherMonad
can offer composed implementations ofpure
andflatMap
for free, simply by relying on the othermonad's
implementation of both, as well as their own privileged knowledge about how to merge the nestedflatMap
call. This can be thought of as "gluing" together twomonads
, 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 duringflatmapping
.For more information, read more about monad transformers.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <B> MonadT<M,B,MT,T>
discardL(Applicative<B,MT> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.default <B> MonadT<M,A,MT,T>
discardR(Applicative<B,MT> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.<B> MonadT<M,B,MT,T>
flatMap(Fn1<? super A,? extends Monad<B,MT>> f)
Chain dependent computations that may continue or short-circuit based on previous results.default <B> MonadT<M,B,MT,T>
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.default <B> Lazy<? extends MonadT<M,B,MT,T>>
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,MT>> 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,N extends MonadRec<?,N>>
MonadT<N,B,?,T>lift(MonadRec<B,N> mb)
<B> MonadT<M,B,MT,T>
pure(B b)
Lift the valueb
into this applicative functor.default <B> MonadT<M,B,MT,T>
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 Detail
-
flatMap
<B> MonadT<M,B,MT,T> flatMap(Fn1<? super A,? extends Monad<B,MT>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
-
pure
<B> MonadT<M,B,MT,T> pure(B b)
Lift the valueb
into this applicative functor.- Specified by:
pure
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
pure
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
pure
in 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
default <B> MonadT<M,B,MT,T> 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.- Specified by:
fmap
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceFunctor<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in 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
default <B> MonadT<M,B,MT,T> 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.- Specified by:
zip
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
zip
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
zip
in 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,MT,T>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,MT>> 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>,A>
- Specified by:
lazyZip
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
lazyZip
in 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:
Maybe
,Either
-
discardL
default <B> MonadT<M,B,MT,T> discardL(Applicative<B,MT> appB)
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>,A>
- Specified by:
discardL
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
discardL
in 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
default <B> MonadT<M,A,MT,T> discardR(Applicative<B,MT> appB)
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>,A>
- Specified by:
discardR
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
discardR
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Type Parameters:
B
- the type of appB's parameter- Parameters:
appB
- the other Applicative- Returns:
- this Applicative
-
-