pub fn compose<'a, A, B, C, F, G>(
f: F,
) -> impl Fn(G) -> Box<dyn Fn(A) -> C + 'a>
Expand description
Takes functions f
and g
and returns the function f . g
(f
composed with g
).
§Type Signature
forall a b c. (b -> c) -> (a -> b) -> a -> c
§Parameters
f
: A function from values of typeB
to values of typeC
.g
: A function from values of typeA
to values of typeB
.
§Returns
A function from values of type A
to values of type C
.
§Examples
use fp_library::functions::compose;
let add_one = |x: i32| x + 1;
let times_two = |x: i32| x * 2;
let times_two_add_one = compose(add_one)(times_two);
assert_eq!(times_two_add_one(3), 7); // 3 * 2 + 1 = 7