separate

Function separate 

Source
pub fn separate<'a, Brand: Compactable, E: 'a, O: 'a>(
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> Pair<<Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>>
Expand description

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

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

§Type Signature

forall e a f. Compactable f => f (Result a e) -> (f a, f e)

§Type Parameters

  • Brand: The brand of the compactable structure.
  • E: The type of the error values.
  • O: The type of the success values.

§Parameters

  • fa: The data structure containing Result values.

§Returns

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

§Examples

use fp_library::classes::compactable::separate;
use fp_library::brands::OptionBrand;
use fp_library::types::Pair;

let x: Option<Result<i32, &str>> = Some(Ok(5));
let Pair(oks, errs) = separate::<OptionBrand, _, _>(x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);