Skip to main content

ref_separate

Function ref_separate 

Source
pub fn ref_separate<'a, Brand: RefCompactable, E: 'a + Clone, O: 'a + Clone>(
    fa: &<Brand as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> (<Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>)
Expand description

Separates a borrowed data structure of Results into two data structures: one containing the cloned Err values and one containing the cloned Ok values.

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

§Type Signature

forall Brand E O. RefCompactable Brand => &Brand (Result O E) -> (Brand E, Brand O)

§Type Parameters

  • 'a: The lifetime of the elements.
  • Brand: The brand of the compactable structure.
  • E: The type of the error values. Must be Clone because elements are extracted from a borrowed container.
  • O: The type of the success values. Must be Clone because elements are extracted from a borrowed container.

§Parameters

  • fa: A reference to the data structure containing Result values.

§Returns

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

§Examples

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

let v: Vec<Result<i32, &str>> = vec![Ok(1), Err("bad"), Ok(3)];
let (errs, oks) = separate::<VecBrand, _, _, _, _>(&v);
assert_eq!(oks, vec![1, 3]);
assert_eq!(errs, vec!["bad"]);