Skip to main content

partition_map

Function partition_map 

Source
pub fn partition_map<'a, Brand: Filterable, A: 'a, E: 'a, O: 'a, Func>(
    func: Func,
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> (<Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>)
where Func: Fn(A) -> Result<O, E> + 'a,
Expand description

Partitions a data structure based on a function that returns a Result.

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

§Type Signature

forall Brand A E O. Filterable Brand => (A -> Result O E, Brand A) -> (Brand E, Brand O)

§Type Parameters

  • 'a: The lifetime of the elements.
  • Brand: The brand of the filterable structure.
  • A: The type of the elements in the input structure.
  • E: The type of the error values.
  • O: The type of the success values.
  • Func: The type of the function to apply.

§Parameters

  • func: The function to apply to each element, returning a Result.
  • fa: The data structure to partition.

§Returns

A pair of data structures: the first containing the Err values, and the second containing the Ok values.

§Examples

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

let x = Some(5);
let (errs, oks) = partition_map::<OptionBrand, _, _, _, _>(|a| if a > 2 { Ok(a) } else { Err(a) }, x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);