Skip to main content

map_ref

Function map_ref 

Source
pub fn map_ref<'a, Brand: RefFunctor, B: 'a, A: 'a, F>(
    f: F,
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>
where F: FnOnce(&A) -> B + 'a,
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 f b a. RefFunctor f => (a -> b, f a) -> f b

§Type Parameters

  • Brand: The brand of the functor.
  • B: The type of the result(s) of applying the function.
  • A: The type of the value(s) inside the functor.
  • F: The type of the function to apply.

§Parameters

  • f: 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::*,
    classes::*,
    types::*,
    functions::map_ref,
};

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