fp_library/typeclasses/
applicative.rs

1use crate::typeclasses::{Apply, ApplyFirst, ApplySecond, Functor, Pure};
2
3pub trait Applicative: Functor + Pure + Apply + ApplyFirst + ApplySecond {}
4
5/// Blanket implementation for the [`Applicative`] typeclass.
6///
7/// Any type that implements all the required supertraits automatically implements [`Applicative`].
8impl<T> Applicative for T where T: Functor + Pure + Apply + ApplyFirst + ApplySecond {}
9
10#[cfg(test)]
11mod tests {
12	use crate::{
13		brands::OptionBrand,
14		typeclasses::Applicative,
15		types::{ResultWithErrBrand, ResultWithOkBrand, SoloBrand, VecBrand},
16	};
17
18	/// Asserts that a type implements [`Applicative`].
19	fn assert_applicative<T: Applicative>() {}
20
21	#[test]
22	/// Assert that brands implementing the required supertraits ([`Functor`],
23	/// [`Pure`], [`Apply`], [`ApplyFirst`], [`ApplySecond`]) also implement
24	/// [`Applicative`].
25	fn test_brands_implement_applicative() {
26		assert_applicative::<SoloBrand>();
27		assert_applicative::<OptionBrand>();
28		assert_applicative::<ResultWithErrBrand<()>>();
29		assert_applicative::<ResultWithOkBrand<()>>();
30		assert_applicative::<VecBrand>();
31	}
32}