fp_library/functions.rs
1//! Generic, free helper functions, combinators and re-exports of [typeclass][crate::typeclasses]
2//! functions that dispatch to instance methods.
3
4pub use super::typeclasses::{
5 apply::apply, apply_first::apply_first, apply_second::apply_second, bind::bind, functor::map,
6 pure::pure,
7};
8
9/// Returns its input.
10///
11/// forall a. a -> a
12///
13/// Examples
14///
15/// ```rust
16/// use fp_library::{functions::identity};
17/// assert_eq!(identity(()), ());
18/// ```
19pub fn identity<A>(a: A) -> A {
20 a
21}
22
23/// Returns its first argument.
24///
25/// forall a b. a -> b -> a
26///
27/// Examples
28///
29/// ```rust
30/// use fp_library::{functions::constant};
31/// assert_eq!(constant(true)(false), true);
32/// ```
33pub fn constant<A, B>(a: A) -> impl Fn(B) -> A
34where
35 A: Clone,
36 B: Clone,
37{
38 move |_b| a.to_owned()
39}