filter

Function filter 

Source
pub fn filter<'a, Brand: Filterable, Func, A: 'a + Clone>(
    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 a f. Filterable f => (a -> bool) -> f a -> f a

§Type Parameters

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

§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::classes::filterable::filter;
use fp_library::brands::OptionBrand;

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