fp_library/typeclasses/
sequence.rs

1use crate::hkt::{Apply, Kind};
2
3pub trait Sequence {
4	/// forall a b. Sequence f => f (a -> b) -> f a -> f b
5	fn sequence<F, A, B>(ff: Apply<Self, F>) -> impl Fn(Apply<Self, A>) -> Apply<Self, B>
6	where
7		Self: Kind<F> + Kind<A> + Kind<B>,
8		F: Fn(A) -> B,
9		Apply<Self, F>: Clone;
10}
11
12/// forall a b. Sequence f => f (a -> b) -> f a -> f b
13pub fn sequence<Brand, F, A, B>(ff: Apply<Brand, F>) -> impl Fn(Apply<Brand, A>) -> Apply<Brand, B>
14where
15	Brand: Kind<F> + Kind<A> + Kind<B> + Sequence,
16	F: Fn(A) -> B,
17	Apply<Brand, F>: Clone,
18{
19	move |fa| Brand::sequence::<F, _, _>(ff.to_owned())(fa)
20}