pub trait Compactable: Kind_cdc7cd43dac7585f {
// Required methods
fn compact<'a, A: 'a>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>;
fn separate<'a, O: 'a, E: 'a>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>;
}Expand description
A type class for data structures that can be compacted and separated.
Compactable allows for:
compact: Filtering outNonevalues and unwrappingSomevalues from a structure ofOptions.separate: Splitting a structure ofResults into a pair of structures, one containing theErrvalues and the other containing theOkvalues.
Required Methods§
Sourcefn compact<'a, A: 'a>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn compact<'a, A: 'a>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Compacts a data structure of Options, discarding None values and keeping Some values.
§Type Signature
forall a f. Compactable f => f (Option a) -> f a
§Type Parameters
A: The type of the elements in theOption.
§Parameters
fa: The data structure containingOptionvalues.
§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));
let z = Some(None::<i32>);
let w = compact::<OptionBrand, _>(z);
assert_eq!(w, None);Sourcefn separate<'a, O: 'a, E: 'a>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>
fn separate<'a, O: 'a, E: 'a>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>, ) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>
Separates a data structure of Results into two data structures: one containing the Ok values and one containing the Err values.
§Type Signature
forall o e f. Compactable f => f (Result o e) -> (f o, f e)
§Type Parameters
O: The type of the success values.E: The type of the error values.
§Parameters
fa: The data structure containingResultvalues.
§Returns
A pair of data structures: the first containing the Ok values, and the second containing the Err values.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let x: Option<Result<i32, &str>> = Some(Ok(5));
let Pair(oks, errs) = separate::<OptionBrand, _, _>(x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);
let y: Option<Result<i32, &str>> = Some(Err("error"));
let Pair(oks2, errs2) = separate::<OptionBrand, _, _>(y);
assert_eq!(oks2, None);
assert_eq!(errs2, Some("error"));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.