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