Skip to main content

alt

Function alt 

Source
pub fn alt<'a, FA, A: 'a + Clone, Brand>(
    fa1: FA,
    fa2: FA,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
where Brand: Kind_cdc7cd43dac7585f, FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A> + AltDispatch<'a, Brand, A, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
Expand description

Combines two values in a context, inferring the brand from the container type.

The Brand type parameter is inferred from the concrete type of fa1 via the InferableBrand trait. Both owned and borrowed containers are supported.

For types with multiple brands, use explicit::alt with a turbofish.

§Type Signature

forall Brand A. Alt Brand => (Brand A, Brand A) -> Brand A

§Type Parameters

  • 'a: The lifetime of the values.
  • FA: The container type (owned or borrowed). Brand is inferred from this.
  • A: The type of the value(s) inside the functor.
  • Brand: The brand, inferred via InferableBrand from FA and the element type.

§Parameters

  • fa1: The first container (owned or borrowed).
  • fa2: The second container (same ownership as the first).

§Returns

A new container from the combination of both inputs.

§Examples

use fp_library::functions::*;

assert_eq!(alt(None, Some(5)), Some(5));

let x = vec![1, 2];
let y = vec![3, 4];
assert_eq!(alt(&x, &y), vec![1, 2, 3, 4]);