fp_library/typeclasses/functor.rs
1use crate::hkt::{Apply, Kind};
2
3pub trait Functor {
4 /// forall 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}
10
11/// forall a b. Functor f => (a -> b) -> f a -> f b
12pub fn map<Brand, F, A, B>(f: F) -> impl Fn(Apply<Brand, A>) -> Apply<Brand, B>
13where
14 Brand: Kind<A> + Kind<B> + Functor,
15 F: Fn(A) -> B,
16{
17 move |fa| Brand::map::<_, _, _>(&f)(fa)
18}