Skip to main content

filter

Function filter 

Source
pub fn filter<'a, Brand: Filterable, A: 'a + Clone, Func>(
    func: Func,
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
where Func: Fn(A) -> bool + 'a,
Expand description

Filters a data structure based on a predicate.

Free function version that dispatches to the type class’ associated function.

§Type Signature

forall f a. Filterable f => (a -> bool, f a) -> f a

§Type Parameters

  • Brand: The brand of the filterable structure.
  • A: The type of the elements in the structure.
  • Func: The type of the predicate function.

§Parameters

  • func: The predicate function.
  • fa: The data structure to filter.

§Returns

A new data structure containing only the elements that satisfy the predicate.

§Examples

use fp_library::{brands::*, functions::*};

let x = Some(5);
let y = filter::<OptionBrand, _, _>(|a| a > 2, x);
assert_eq!(y, Some(5));