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