pub fn separate<'a, Brand: Kind_cdc7cd43dac7585f, E: 'a, O: 'a, FA, Marker>(
fa: FA,
) -> (<Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>)where
FA: SeparateDispatch<'a, Brand, E, O, Marker>,Expand description
Separates a container of Result values into two containers.
Dispatches to either Compactable::separate or RefCompactable::ref_separate
based on whether the container is owned or borrowed.
The dispatch is resolved at compile time with no runtime cost.
§Type Signature
forall Brand E O. Compactable Brand => FA -> (Brand E, Brand O)
§Type Parameters
'a: The lifetime of the values.Brand: The brand of the compactable.E: The error type inside theResultwrappers.O: The success type inside theResultwrappers.FA: The container type (owned or borrowed), inferred from the argument.Marker: Dispatch marker type, inferred automatically.
§Parameters
fa: The container ofResultvalues (owned or borrowed).
§Returns
A tuple of two containers: Err values and Ok values.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
// Owned
let (errs, oks) = separate::<VecBrand, _, _, _, _>(vec![Ok(1), Err(2), Ok(3)]);
assert_eq!(oks, vec![1, 3]);
assert_eq!(errs, vec![2]);
// By-ref
let v: Vec<Result<i32, i32>> = vec![Ok(1), Err(2), Ok(3)];
let (errs, oks) = separate::<VecBrand, _, _, _, _>(&v);
assert_eq!(oks, vec![1, 3]);
assert_eq!(errs, vec![2]);