Skip to main content

compact

Function compact 

Source
pub fn compact<'a, FA, A: 'a, Brand>(
    fa: FA,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
where Brand: Kind_cdc7cd43dac7585f, FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, Option<A>> + CompactDispatch<'a, Brand, A, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, Option<A>>>::Marker>,
Expand description

Removes None values from a container of Options, 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::compact with a turbofish.

§Type Signature

forall Brand A. Compactable Brand => Brand (Option A) -> Brand A

§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 Option wrappers.
  • Brand: The brand, inferred via InferableBrand from FA and the element type.

§Parameters

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

§Returns

A new container with None values removed and Some values unwrapped.

§Examples

use fp_library::functions::*;

assert_eq!(compact(vec![Some(1), None, Some(3)]), vec![1, 3]);

let v = vec![Some(1), None, Some(3)];
assert_eq!(compact(&v), vec![1, 3]);