Skip to main content

FunctorFilter

Trait FunctorFilter 

Source
pub trait FunctorFilter: Functor {
    // Required method
    fn filter_map<A, B>(
        fa: Self::Of<A>,
        f: impl Fn(A) -> Option<B>,
    ) -> Self::Of<B>;

    // Provided method
    fn filter<A>(fa: Self::Of<A>, pred: impl Fn(&A) -> bool) -> Self::Of<A>
       where A: Clone { ... }
}
Expand description

FunctorFilter: a Functor that can filter elements during mapping.

Laws:

  • Identity: filter_map(fa, Some) == fa
  • Composition: filter_map(filter_map(fa, f), g) == filter_map(fa, |a| f(a).and_then(g))

Required Methods§

Source

fn filter_map<A, B>(fa: Self::Of<A>, f: impl Fn(A) -> Option<B>) -> Self::Of<B>

Provided Methods§

Source

fn filter<A>(fa: Self::Of<A>, pred: impl Fn(&A) -> bool) -> Self::Of<A>
where A: Clone,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl FunctorFilter for OptionF

Source§

impl FunctorFilter for VecF

Available on crate features alloc or std only.