fp_library/functions.rs
1//! Generic, free helper functions, combinators and typeclass functions that
2//! 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/// forall a. a -> a
10///
11/// Returns its input.
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/// forall a b. a -> b -> a
24///
25/// Returns its first argument.
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}