Skip to main content

compact

Function compact 

Source
pub fn compact<'a, Brand: Compactable, A: 'a>(
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
Expand description

Compacts a data structure of Options, discarding None values and keeping Some values.

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

§Type Signature

forall brand a. Compactable brand => brand (Option a) -> brand a

§Type Parameters

  • 'a: The lifetime of the elements.
  • Brand: The brand of the compactable structure.
  • A: The type of the elements in the Option.

§Parameters

  • fa: The data structure containing Option values.

§Returns

A new data structure containing only the values from the Some variants.

§Examples

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

let x = Some(Some(5));
let y = compact::<OptionBrand, _>(x);
assert_eq!(y, Some(5));