fp_core/
functor.rs

1use crate::hkt::HKT;
2
3pub trait Functor<B>: HKT<B> {
4    fn fmap<F>(self, f: F) -> Self::Target
5    where
6        F: FnOnce(Self::Current) -> B;
7}
8
9impl<A, B> Functor<B> for Option<A> {
10    fn fmap<F>(self, f: F) -> Self::Target
11    where
12        // A is Self::Current
13        F: FnOnce(A) -> B,
14    {
15        self.map(f)
16    }
17}
18
19impl<A, B, E> Functor<B> for Result<A, E> {
20    fn fmap<F>(self, f: F) -> Self::Target
21    where
22        // A is Self::Current
23        F: FnOnce(A) -> B,
24    {
25        self.map(f)
26    }
27}