Skip to main content

Module map_first

Module map_first 

Source
Expand description

Dispatch for Bifunctor::map_first and RefBifunctor::ref_map_first.

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

Corresponds to lmap in both Haskell and PureScript.

§Examples

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

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

// By-ref: dispatches to RefBifunctor::ref_map_first
let x = Result::<i32, i32>::Err(5);
let y = map_first::<ResultBrand, _, _, _, _, _>(|e: &i32| *e * 2, &x);
assert_eq!(y, Err(10));

Modules§

explicit
Explicit dispatch functions requiring a Brand turbofish.

Traits§

MapFirstDispatch
Trait that routes a map_first operation to the appropriate type class method.

Functions§

map_first
Maps a function over the first type argument of a bifunctor, inferring the brand from the container type.