A
- the type of the parameterM
- the unification parameter to more tightly type-constrain Monads to themselvespublic interface Monad<A,M extends Monad<?,M>> extends Applicative<A,M>
Applicative
functors that support a flattening operation to unwrap M<M<A>>
-> M<A>
. This flattening operation, coupled with Applicative.zip(Applicative)
, gives rise to
flatMap(Fn1)
, a binding operation that maps the carrier value to a new monad instance in the same
category, and then unwraps the outer layer.
In addition to the applicative laws, there are 3 specific monad laws that monads should obey:
m.pure(a).flatMap(fn).equals(fn.apply(a))
m.flatMap(m::pure).equals(m)
m.flatMap(f).flatMap(g).equals(m.flatMap(a -> f.apply(a).flatMap(g)))
For more information, read about Monads.
Modifier and Type | Method and Description |
---|---|
default <B> Monad<B,M> |
discardL(Applicative<B,M> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
default <B> Monad<A,M> |
discardR(Applicative<B,M> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
<B> Monad<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> Monad<B,M> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
static <M extends Monad<?,M>,A,MA extends Monad<A,M>> |
join(Monad<? extends MA,M> mma)
|
default <B> Lazy<? extends Monad<B,M>> |
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,M>> 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> Monad<B,M> |
pure(B b)
Lift the value
b into this applicative functor. |
default <B> Monad<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.
|
<B> Monad<B,M> flatMap(Fn1<? super A,? extends Monad<B,M>> f)
B
- the resulting monad parameter typef
- the dependent computation over Adefault <B> Monad<B,M> fmap(Fn1<? super A,? extends B> fn)
default <B> Monad<B,M> zip(Applicative<Fn1<? super A,? extends B>,M> appFn)
default <B> Lazy<? extends Monad<B,M>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,M>> 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.default <B> Monad<B,M> discardL(Applicative<B,M> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.default <B> Monad<A,M> discardR(Applicative<B,M> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.