pub fn map_first<'a, Brand: Kind_266801a817966495, A: 'a, B: 'a, C: 'a, FA, Marker>(
f: impl MapFirstDispatch<'a, Brand, A, B, C, FA, Marker>,
p: FA,
) -> <Brand as Kind_266801a817966495>::Of<'a, B, C>Expand description
Maps a function over the first type argument of a bifunctor.
Corresponds to lmap in both Haskell and PureScript.
Dispatches to either Bifunctor::map_first or
RefBifunctor::ref_map_first based on the closure’s argument type.
The Marker and FA type parameters are inferred automatically by the
compiler. Callers write map_first::<Brand, _, _, _, _>(...) and never
need to specify Marker or FA explicitly.
§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.Brand: The brand of the bifunctor.A: The type of the first value.B: The type of the first result.C: The type of the second value.FA: The container type (owned or borrowed), inferred from the argument.Marker: Dispatch marker type, inferred automatically.
§Parameters
f: The function to apply to the first value.p: The bifunctor value (owned for Val, borrowed for Ref).
§Returns
A new bifunctor with the first value transformed.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
// Owned
let x = Result::<i32, i32>::Err(5);
let y = map_first::<ResultBrand, _, _, _, _, _>(|e| e * 2, x);
assert_eq!(y, Err(10));
// By-ref
let x = Result::<i32, i32>::Err(5);
let y = map_first::<ResultBrand, _, _, _, _, _>(|e: &i32| *e * 2, &x);
assert_eq!(y, Err(10));