higher_cat/liftm1.rs
1use crate::{Bind, Pure};
2use higher::Lift;
3
4/// `LiftM1` provides a default implementation for `Functor::map` using
5/// only `Bind` and `Pure`.
6pub trait LiftM1<A, B>: Bind<A, B>
7where
8 <Self as Lift<A, B>>::Target1: Pure<B>,
9{
10 fn lift_m1<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
11 where
12 F: Fn(A) -> B;
13}
14
15impl<M, A, B> LiftM1<A, B> for M
16where
17 M: Bind<A, B>,
18 <M as Lift<A, B>>::Target1: Pure<B>,
19{
20 fn lift_m1<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
21 where
22 F: Fn(A) -> B,
23 {
24 self.bind(|value| Pure::pure(f(value)))
25 }
26}