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		Apply<Self, (A,)>: Clone,
9		F: Fn(A) -> Apply<Self, (B,)>;
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	Apply<Brand, (A,)>: Clone,
17	F: Fn(A) -> Apply<Brand, (B,)>,
18{
19	move |f| Brand::bind::<F, A, B>(ma.to_owned())(f)
20}