pub trait Applicative:
Functor
+ Pure
+ Apply
+ ApplyFirst
+ ApplySecond { }
Expand description
A typeclass for applicative functors.
Applicative
extends Functor
with the ability to lift values into a context
(pure
) and to apply functions within a context to values within a context
(apply
). It also provides additional operations for combining contexts
(apply_first
, apply_second
).
Applicative functors are more powerful than functors but less powerful than monads. They allow for sequencing computations but with less flexibility than monads since the structure of the computation must be known in advance.
§Laws
Applicative instances must satisfy the following laws:
- Identity:
apply(pure(identity))(v) = v
. - Composition:
apply(apply(apply(pure(compose))(u))(v))(w) = apply(u)(apply(v)(w))
. - Homomorphism:
apply(pure(f))(pure(x)) = pure(f(x))
. - Interchange:
apply(u)(pure(y)) = apply(pure(f => f(y)))(u)
.
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> Applicative for Brand
Blanket implementation for the Applicative
typeclass.
Any type that implements all the required supertraits automatically implements Applicative
.