pub fn partition_map<'a, Brand: Filterable, A: 'a, O: 'a, E: 'a, Func>(
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>>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 o e. Filterable brand => (a -> Result o e, brand a) -> Pair (brand o) (brand e)
§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.O: The type of the success values.E: The type of the error values.Func: The type of the function to apply.
§Parameters
func: The function to apply to each element, returning aResult.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::{brands::*, functions::*, types::*};
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);