Skip to main content

ref_map

Function ref_map 

Source
pub fn ref_map<'a, Brand: RefFunctor, A: 'a, B: 'a>(
    func: impl FnOnce(&A) -> B + 'a,
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>
Expand description

Maps a function over the values in the functor context, where the function takes a reference.

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

§Type Signature

forall Brand A B. RefFunctor Brand => (&A -> B, Brand A) -> Brand B

§Type Parameters

  • 'a: The lifetime of the values.
  • Brand: The brand of the functor.
  • A: The type of the value(s) inside the functor.
  • B: The type of the result(s) of applying the function.

§Parameters

  • func: The function to apply to the value(s) inside the functor.
  • fa: The functor instance containing the value(s).

§Returns

A new functor instance containing the result(s) of applying the function.

§Examples

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

let memo = Lazy::<_, RcLazyConfig>::new(|| 10);
let mapped = ref_map::<LazyBrand<RcLazyConfig>, _, _>(|x: &i32| *x * 2, memo);
assert_eq!(*mapped.evaluate(), 20);