Skip to main content

map_input

Function map_input 

Source
pub fn map_input<'a, Brand: Profunctor, A: 'a, B: 'a, C: 'a>(
    ab: impl Fn(A) -> B + 'a,
    pbc: <Brand as Kind_266801a817966495>::Of<'a, B, C>,
) -> <Brand as Kind_266801a817966495>::Of<'a, A, C>
Expand description

Maps contravariantly over the first argument.

Corresponds to lmap in Haskell and lcmap in PureScript.

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

§Type Signature

forall Brand A B C. Profunctor Brand => (A -> B, Brand B C) -> Brand A C

§Type Parameters

  • 'a: The lifetime of the values.
  • Brand: The brand of the profunctor.
  • A: The new input type.
  • B: The original input type.
  • C: The output type.

§Parameters

  • ab: The contravariant function to apply to the input.
  • pbc: The profunctor instance.

§Returns

A new profunctor instance with transformed input type.

§Examples

use fp_library::{
	brands::*,
	classes::profunctor::*,
	functions::*,
};

let f = |x: i32| x + 1;
let g = map_input::<RcFnBrand, _, _, _>(
	|x: i32| x * 2,
	std::rc::Rc::new(f) as std::rc::Rc<dyn Fn(i32) -> i32>,
);
assert_eq!(g(10), 21); // (10 * 2) + 1 = 21