pub fn alt<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a + Clone, FA, Marker>(
fa1: FA,
fa2: FA,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>where
FA: AltDispatch<'a, Brand, A, Marker>,Expand description
Combines two values in a context, choosing associatively.
Dispatches to either Alt::alt or RefAlt::ref_alt
based on whether the containers are owned or borrowed.
The Marker type parameter is inferred automatically by the
compiler from the container argument. Callers write
alt::<Brand, _>(...) and never need to specify Marker explicitly.
The dispatch is resolved at compile time with no runtime cost.
§Type Signature
forall Brand A. Alt Brand => (Brand A, Brand A) -> Brand A
§Type Parameters
'a: The lifetime of the values.Brand: The brand of the functor.A: The type of the value(s) inside the functor.FA: The container type (owned or borrowed), inferred from the argument.Marker: Dispatch marker type, inferred automatically.
§Parameters
fa1: The first container.fa2: The second container.
§Returns
A new container from the combination of both inputs.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
// Owned: dispatches to Alt::alt
let y = alt::<OptionBrand, _, _, _>(None, Some(5));
assert_eq!(y, Some(5));
// By-ref: dispatches to RefAlt::ref_alt
let x: Option<i32> = None;
let y = Some(5);
let z = alt::<OptionBrand, _, _, _>(&x, &y);
assert_eq!(z, Some(5));