Skip to main content

partition

Function partition 

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

Partitions a data structure based on a predicate.

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

Note: The return order is (satisfied, not_satisfied), matching Rust’s Iterator::partition.

§Type Signature

forall brand a. Filterable brand => (a -> bool, brand a) -> Pair (brand a) (brand a)

§Type Parameters

  • 'a: The lifetime of the elements.
  • 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 partition.

§Returns

A pair of data structures: the first containing elements that satisfy the predicate, and the second containing elements that do not.

§Examples

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

let x = Some(5);
let Pair(satisfied, not_satisfied) = partition::<OptionBrand, _, _>(|a| a > 2, x);
assert_eq!(satisfied, Some(5));
assert_eq!(not_satisfied, None);