Skip to main content

partition_map

Function partition_map 

Source
pub fn partition_map<'a, FA, A: 'a, E: 'a, O: 'a, Marker>(
    f: impl PartitionMapDispatch<'a, <FA as InferableBrand_cdc7cd43dac7585f>::Brand, A, E, O, FA, Marker>,
    fa: FA,
) -> (<<FA as InferableBrand_cdc7cd43dac7585f>::Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>, <<FA as InferableBrand_cdc7cd43dac7585f>::Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>)
Expand description

Partitions the values using a function returning Result, inferring the brand from the container type.

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

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

§Type Signature

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

§Type Parameters

  • 'a: The lifetime of the values.
  • FA: The container type (owned or borrowed). Brand is inferred from this.
  • A: The type of the value(s) inside the filterable.
  • E: The error type produced by the partitioning function.
  • O: The success type produced by the partitioning function.
  • Marker: Dispatch marker type, inferred automatically.

§Parameters

  • f: The function to apply to each value. Returns Ok(o) or Err(e).
  • fa: The filterable instance (owned or borrowed).

§Returns

A tuple of two filterable instances: Err values and Ok values.

§Examples

use fp_library::functions::*;

let (errs, oks) = partition_map(|x: i32| Ok::<i32, i32>(x * 2), Some(5));
assert_eq!(errs, None);
assert_eq!(oks, Some(10));