Skip to main content

Module profunctor

Module profunctor 

Source
Expand description

Profunctors, which are functors contravariant in the first argument and covariant in the second.

A profunctor represents a morphism between two categories, mapping objects and morphisms from one to the other.

§Examples

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

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

Re-exports§

pub use choice::*;
pub use closed::*;
pub use cochoice::*;
pub use costrong::*;
pub use strong::*;
pub use wander::*;

Modules§

choice
Choice profunctors, which can lift profunctors through sum types.
closed
Profunctors that can be closed under exponentiation.
cochoice
Cochoice profunctors, the dual of Choice.
costrong
Costrong profunctors, the dual of Strong.
strong
Strong profunctors, which can lift profunctors through product types.
wander
Profunctors that support traversing structures.

Traits§

Profunctor
A type class for profunctors.

Functions§

arrow
Lifts a pure function into a profunctor context.
dimap
Maps over both arguments of the profunctor.
map_input
Maps contravariantly over the first argument.
map_output
Maps covariantly over the second argument.