Skip to main content

ref_map_first

Function ref_map_first 

Source
pub fn ref_map_first<'a, Brand: RefBifunctor, A: 'a, B: 'a, C: Clone + 'a>(
    f: impl Fn(&A) -> B + 'a,
    p: &<Brand as Kind_266801a817966495>::Of<'a, A, C>,
) -> <Brand as Kind_266801a817966495>::Of<'a, B, C>
Expand description

Maps a function over the first type argument of the bifunctor by reference.

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

§Type Signature

forall Brand A B C. RefBifunctor 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 (must be Clone).

§Parameters

  • f: The function to apply to the first value.
  • p: The bifunctor instance (borrowed).

§Returns

A new bifunctor instance with the first value transformed.

§Examples

use fp_library::{
	brands::*,
	classes::ref_bifunctor::*,
};

let x = Result::<i32, i32>::Err(5);
let y = ref_map_first::<ResultBrand, _, _, _>(|e: &i32| *e * 2, &x);
assert_eq!(y, Err(10));