M
- the argument monad
A
- the carrier typeMT
- the Monad
witnessT
- the MonadT
witnesspublic 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>
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.
Modifier and Type | Method and Description |
---|---|
default <B> MonadT<M,B,MT,T> |
discardL(Applicative<B,MT> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
default <B> MonadT<M,A,MT,T> |
discardR(Applicative<B,MT> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
<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 a
lazy 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>> |
lift(MonadRec<B,N> mb)
|
<B> MonadT<M,B,MT,T> |
pure(B b)
Lift the value
b 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.
|
trampolineM
<B> MonadT<M,B,MT,T> flatMap(Fn1<? super A,? extends Monad<B,MT>> f)
<B> MonadT<M,B,MT,T> pure(B b)
b
into this applicative functor.pure
in interface Applicative<A,MT extends MonadT<M,?,MT,T>>
pure
in interface Monad<A,MT extends MonadT<M,?,MT,T>>
pure
in interface MonadRec<A,MT extends MonadT<M,?,MT,T>>
B
- the type of the returned applicative's parameterb
- the valuedefault <B> MonadT<M,B,MT,T> fmap(Fn1<? super A,? extends B> fn)
fmap
in interface Applicative<A,MT extends MonadT<M,?,MT,T>>
fmap
in interface Functor<A,MT extends MonadT<M,?,MT,T>>
fmap
in interface Monad<A,MT extends MonadT<M,?,MT,T>>
fmap
in interface MonadRec<A,MT extends MonadT<M,?,MT,T>>
B
- the new parameter typefn
- the mapping functiondefault <B> MonadT<M,B,MT,T> zip(Applicative<Fn1<? super A,? extends B>,MT> appFn)
zip
in interface Applicative<A,MT extends MonadT<M,?,MT,T>>
zip
in interface Monad<A,MT extends MonadT<M,?,MT,T>>
zip
in interface MonadRec<A,MT extends MonadT<M,?,MT,T>>
B
- the resulting applicative parameter typeappFn
- the other applicative instancedefault <B> Lazy<? extends MonadT<M,B,MT,T>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,MT>> lazyAppFn)
lazy
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.lazyZip
in interface Applicative<A,MT extends MonadT<M,?,MT,T>>
lazyZip
in interface Monad<A,MT extends MonadT<M,?,MT,T>>
lazyZip
in interface MonadRec<A,MT extends MonadT<M,?,MT,T>>
B
- the resulting applicative parameter typelazyAppFn
- the lazy other applicative instanceMaybe
,
Either
default <B> MonadT<M,B,MT,T> discardL(Applicative<B,MT> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.discardL
in interface Applicative<A,MT extends MonadT<M,?,MT,T>>
discardL
in interface Monad<A,MT extends MonadT<M,?,MT,T>>
discardL
in interface MonadRec<A,MT extends MonadT<M,?,MT,T>>
B
- the type of the returned Applicative's parameterappB
- the other Applicativedefault <B> MonadT<M,A,MT,T> discardR(Applicative<B,MT> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.discardR
in interface Applicative<A,MT extends MonadT<M,?,MT,T>>
discardR
in interface Monad<A,MT extends MonadT<M,?,MT,T>>
discardR
in interface MonadRec<A,MT extends MonadT<M,?,MT,T>>
B
- the type of appB's parameterappB
- the other Applicative