pub fn map_first<'a, FA, A: 'a, B: 'a, C: 'a, Brand>(
f: impl MapFirstDispatch<'a, Brand, A, B, C, FA, <FA as InferableBrand_266801a817966495<'a, Brand, A, C>>::Marker>,
p: FA,
) -> <Brand as Kind_266801a817966495>::Of<'a, B, C>where
Brand: Kind_266801a817966495,
FA: InferableBrand_266801a817966495<'a, Brand, A, C>,Expand description
Maps a function over the first type argument of a bifunctor, inferring the brand from the container type.
Corresponds to lmap in both Haskell and PureScript.
The Brand type parameter is inferred from the concrete type of p via
the InferableBrand trait. Both owned and borrowed containers are
supported.
For types that need an explicit brand, use
explicit::map_first with a turbofish.
§Type Signature
forall Brand A B C. Bifunctor Brand => (A -> B, Brand A C) -> Brand B C
§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 first value.B: The type of the first result.C: The type of the second value.Brand: The brand, inferred via InferableBrand from FA and the element types.
§Parameters
f: The function to apply to the first value.p: The bifunctor value (owned or borrowed).
§Returns
A new bifunctor with the first value transformed.
§Examples
use fp_library::functions::*;
// Brand inferred from Result<i32, String>
let x: Result<String, i32> = Err(5);
let y = map_first(|e| e * 2, x);
assert_eq!(y, Err(10));