pub struct VecWitness;Expand description
Re-exports VecWitness, the HKT witness for Vec<T>.
VecWitness is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness
for the Vec<T> type constructor. It allows Vec to be used with generic
functional programming traits like Functor, Applicative, Foldable, and Monad.
By implementing HKT for VecWitness, we can write generic functions that operate
on any type that has the “shape” of Vec, without knowing the inner type T.
Trait Implementations§
Source§impl Applicative<VecWitness> for VecWitness
impl Applicative<VecWitness> for VecWitness
Source§fn apply<A, B, Func>(
f_ab: <VecWitness as HKT>::Type<Func>,
f_a: <VecWitness as HKT>::Type<A>,
) -> <VecWitness as HKT>::Type<B>
fn apply<A, B, Func>( f_ab: <VecWitness as HKT>::Type<Func>, f_a: <VecWitness as HKT>::Type<A>, ) -> <VecWitness as HKT>::Type<B>
Applies a vector of functions (f_ab) to a vector of values (f_a).
Each function in f_ab is applied to each value in f_a, producing a new vector
containing all possible combinations of applications.
§Arguments
f_ab: AVeccontaining functions.f_a: AVeccontaining arguments.
§Returns
A new Vec with the results of applying each function to each value.
Source§impl Foldable<VecWitness> for VecWitness
impl Foldable<VecWitness> for VecWitness
Source§impl Functor<VecWitness> for VecWitness
impl Functor<VecWitness> for VecWitness
Source§fn fmap<A, B, Func>(
m_a: <VecWitness as HKT>::Type<A>,
f: Func,
) -> <VecWitness as HKT>::Type<B>where
Func: FnMut(A) -> B,
fn fmap<A, B, Func>(
m_a: <VecWitness as HKT>::Type<A>,
f: Func,
) -> <VecWitness as HKT>::Type<B>where
Func: FnMut(A) -> B,
Source§impl HKT for VecWitness
impl HKT for VecWitness
Source§impl Monad<VecWitness> for VecWitness
impl Monad<VecWitness> for VecWitness
Source§fn bind<A, B, Func>(
m_a: <VecWitness as HKT>::Type<A>,
f: Func,
) -> <VecWitness as HKT>::Type<B>
fn bind<A, B, Func>( m_a: <VecWitness as HKT>::Type<A>, f: Func, ) -> <VecWitness as HKT>::Type<B>
Implements the bind (or flat_map) operation for Vec<T>.
Applies the function f to each element in the vector, where f itself
returns a new vector. All the resulting vectors are then concatenated into a single Vec.
This is useful for chaining computations that produce multiple results.
§Arguments
m_a: The initialVec.f: A function that takes an inner value and returns a newVec.
§Returns
A new Vec representing the chained and flattened computation.