Function compose

Source
pub fn compose<'a, A, B, C, F, G>(
    f: F,
) -> impl Fn(G) -> Box<dyn Fn(A) -> C + 'a>
where F: Fn(B) -> C + Clone + 'a, G: Fn(A) -> B + 'a,
Expand description

Takes a function f, returns a new function that takes a function g, then returns the final composed function f . g.

forall a b c. (b -> c) -> (a -> b) -> a -> 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