Skip to main content

map_second

Function map_second 

Source
pub fn map_second<'a, Brand: Bifunctor, A: 'a, B: 'a, C: 'a>(
    g: impl Fn(B) -> C + 'a,
    p: <Brand as Kind_266801a817966495>::Of<'a, A, B>,
) -> <Brand as Kind_266801a817966495>::Of<'a, A, C>
Expand description

Maps a function over the second type argument of the bifunctor.

Corresponds to rmap in both Haskell and PureScript.

Free function version that dispatches to the type class’ associated function.

§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.

§Parameters

  • g: The function to apply to the second value.
  • p: The bifunctor instance.

§Returns

A new bifunctor instance with the second value transformed.

§Examples

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

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

let x = Result::<i32, i32>::Err(5);
let y = map_second::<ResultBrand, _, _, _, _, _>(|s| s * 2, x);
assert_eq!(y, Err(5));