fp_library/typeclasses/
apply.rs

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