partition_map

Function partition_map 

Source
pub fn partition_map<'a, Brand: Filterable, Func, A: 'a, E: 'a, O: 'a>(
    func: Func,
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Pair<<Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>>
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 a e o f. Filterable f => (a -> Result o e) -> f a -> (f o, f e)

§Type Parameters

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

§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 Ok values, and the second containing the Err values.

§Examples

use fp_library::classes::filterable::partition_map;
use fp_library::brands::OptionBrand;
use fp_library::types::Pair;

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