Skip to main content

separate

Function separate 

Source
pub fn separate<'a, FA, E: 'a, O: 'a, Brand>(
    fa: FA,
) -> (<Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>)
where Brand: Kind_cdc7cd43dac7585f, FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, Result<O, E>> + SeparateDispatch<'a, Brand, E, O, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, Result<O, E>>>::Marker>,
Expand description

Separates a container of Result values into two containers, inferring the brand from the container type.

The Brand type parameter is inferred from the concrete type of fa via the InferableBrand trait. Both owned and borrowed containers are supported.

For types with multiple brands, use explicit::separate with a turbofish.

§Type Signature

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

§Type Parameters

  • 'a: The lifetime of the values.
  • FA: The container type (owned or borrowed). Brand is inferred from this.
  • E: The error type inside the Result wrappers.
  • O: The success type inside the Result wrappers.
  • Brand: The brand, inferred via InferableBrand from FA and the element type.

§Parameters

  • fa: The container of Result values (owned or borrowed).

§Returns

A tuple of two containers: Err values and Ok values.

§Examples

use fp_library::functions::*;

let (errs, oks) = separate(vec![Ok(1), Err(2), Ok(3)]);
assert_eq!(oks, vec![1, 3]);
assert_eq!(errs, vec![2]);