Skip to main content

map

Function map 

Source
pub fn map<'a, Brand: Functor, A: 'a, B: 'a, Func>(
    f: Func,
    fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>
where Func: Fn(A) -> B + 'a,
Expand description

Maps a function over the values in the functor context.

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

§Type Signature

forall brand a b. Functor 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.
  • Func: 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::*, functions::*};

let x = Some(5);
let y = map::<OptionBrand, _, _, _>(|i| i * 2, x);
assert_eq!(y, Some(10));