fp_library/typeclasses/
functor.rs

1use crate::hkt::{Apply, Kind};
2
3pub trait Functor {
4	/// forall f a b. Functor f => (a -> b) -> f a -> f b
5	fn map<F, A, B>(f: &F) -> impl Fn(&Apply<Self, A>) -> Apply<Self, B>
6	where
7		Self: Kind<A> + Kind<B>,
8		F: Fn(&A) -> B,
9		A: Clone;
10}
11
12/// forall f a b. Functor f => (a -> b) -> f a -> f b
13pub fn map<Brand, F, A, B>(f: &F) -> impl Fn(&Apply<Brand, A>) -> Apply<Brand, B>
14where
15	Brand: Kind<A> + Kind<B> + Functor,
16	F: Fn(&A) -> B,
17	A: Clone,
18{
19	|fa| Brand::map::<_, _, _>(f)(fa)
20}