Skip to main content

apply_first

Function apply_first 

Source
pub fn apply_first<'a, FA, A: 'a, B: 'a, Brand>(
    fa: FA,
    fb: <FA as ApplyFirstDispatch<'a, Brand, A, B, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>>::FB,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
where Brand: Kind_cdc7cd43dac7585f, FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A> + ApplyFirstDispatch<'a, Brand, A, B, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
Expand description

Sequences two applicative actions, keeping the result of the first, inferring the brand from the container type.

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

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

§Type Signature

forall Brand A B. ApplyFirst Brand => (Brand A, Brand B) -> Brand A

§Type Parameters

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

§Parameters

  • fa: The first container (its values are preserved).
  • fb: The second container (its values are discarded).

§Returns

A container preserving the values from the first input.

§Examples

use fp_library::functions::*;

assert_eq!(apply_first(Some(5), Some(10)), Some(5));

let a = Some(5);
let b = Some(10);
assert_eq!(apply_first(&a, &b), Some(5));