pub fn compact<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, FA, Marker>(
fa: FA,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>where
FA: CompactDispatch<'a, Brand, A, Marker>,Expand description
Removes None values from a container of Options, unwrapping the Some values.
Dispatches to either Compactable::compact or RefCompactable::ref_compact
based on whether the container is owned or borrowed.
The dispatch is resolved at compile time with no runtime cost.
§Type Signature
forall Brand A. Compactable Brand => FA -> Brand A
§Type Parameters
'a: The lifetime of the values.Brand: The brand of the compactable.A: The type of the value(s) inside theOptionwrappers.FA: The container type (owned or borrowed), inferred from the argument.Marker: Dispatch marker type, inferred automatically.
§Parameters
fa: The container ofOptionvalues (owned or borrowed).
§Returns
A new container with None values removed and Some values unwrapped.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
// Owned
let y = compact::<VecBrand, _, _, _>(vec![Some(1), None, Some(3)]);
assert_eq!(y, vec![1, 3]);
// By-ref
let v = vec![Some(1), None, Some(3)];
let y = compact::<VecBrand, _, _, _>(&v);
assert_eq!(y, vec![1, 3]);