pub trait Applicative<F: HKT>: Functor<F> {
// Required methods
fn pure<T>(value: T) -> F::Type<T>;
fn apply<A, B, Func>(f_ab: F::Type<Func>, f_a: F::Type<A>) -> F::Type<B>
where Func: FnMut(A) -> B,
A: Clone;
}Expand description
Re-exports the Applicative trait for applying functions within a context.
The Applicative trait extends Functor by providing methods to apply a function
wrapped in a context to a value wrapped in a context, and to lift a pure value
into the minimal context.
This trait is generic over F, which is a Higher-Kinded Type (HKT) witness.
§Laws (Informal)
- Identity:
pure(id).apply(v) == v - Homomorphism:
pure(f).apply(pure(x)) == pure(f(x)) - Interchange:
u.apply(pure(y)) == pure(|f| f(y)).apply(u)
§Type Parameters
F: A Higher-Kinded Type (HKT) witness that represents the type constructor (e.g.,OptionWitness,ResultWitness<E>).
Required Methods§
Sourcefn apply<A, B, Func>(f_ab: F::Type<Func>, f_a: F::Type<A>) -> F::Type<B>
fn apply<A, B, Func>(f_ab: F::Type<Func>, f_a: F::Type<A>) -> F::Type<B>
Applies a function wrapped in a context (f_ab) to a value wrapped in a context (f_a).
This allows sequencing computations where both the function and its argument are within the same applicative context.
§Arguments
f_ab: An instance ofF::Type<Func>containing the function to apply.f_a: An instance ofF::Type<A>containing the argument for the function.
§Returns
An instance of F::Type<B> containing the result of the application,
or an appropriate error/empty context if either f_ab or f_a is in an
error/empty state.
§Type Parameters
A: The input type of the function.B: The output type of the function.Func: The type of the function, which must beFnMut(A) -> B.
§Examples
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.