pub trait Monad: Applicative + Bind { }
Expand description
A typeclass for monads.
Monad
combines the capabilities of Applicative
and Bind
, providing
a powerful abstraction for sequencing computations with context.
Monads are more powerful than applicative functors because they allow the structure of subsequent computations to depend on the results of previous computations.
§Laws
Monad instances must satisfy the following laws:
- Left identity:
bind(pure(a))(f) = f(a)
. - Right identity:
bind(m)(pure) = m
. - Associativity:
bind(bind(m)(f))(g) = bind(m)(x => bind(f(x))(g))
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<Brand> Monad for Brandwhere
Brand: Applicative + Bind,
Blanket implementation for the Monad
typeclass.
Any type that implements all the required supertraits automatically implements Monad
.