Skip to main content

ref_compact

Function ref_compact 

Source
pub fn ref_compact<'a, Brand: RefCompactable, A: 'a + Clone>(
    fa: &<Brand as Kind_cdc7cd43dac7585f>::Of<'a, Option<A>>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
Expand description

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

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

§Type Signature

forall Brand A. RefCompactable 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. Must be Clone because elements are extracted from a borrowed container.

§Parameters

  • fa: A reference to the data structure containing Option values.

§Returns

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

§Examples

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

let v = vec![Some(1), None, Some(3)];
let result = compact::<VecBrand, _, _, _>(&v);
assert_eq!(result, vec![1, 3]);