Skip to main content

Module map_second

Module map_second 

Source
Expand description

Dispatch for Bifunctor::map_second and RefBifunctor::ref_map_second.

Provides the MapSecondDispatch trait and a unified explicit::map_second free function that routes to the appropriate trait method based on the closure’s argument type.

Corresponds to rmap in both Haskell and PureScript.

§Examples

use fp_library::{
	brands::*,
	functions::explicit::*,
};

// Owned: dispatches to Bifunctor::map_second
let x = Result::<i32, i32>::Ok(5);
let y = map_second::<ResultBrand, _, _, _, _, _>(|s| s * 2, x);
assert_eq!(y, Ok(10));

// By-ref: dispatches to RefBifunctor::ref_map_second
let x = Result::<i32, i32>::Ok(5);
let y = map_second::<ResultBrand, _, _, _, _, _>(|s: &i32| *s * 2, &x);
assert_eq!(y, Ok(10));

Modules§

explicit
Explicit dispatch functions requiring a Brand turbofish.

Traits§

MapSecondDispatch
Trait that routes a map_second operation to the appropriate type class method.

Functions§

map_second
Maps a function over the second type argument of a bifunctor, inferring the brand from the container type.