pub fn compose<A, B, C, F, G>(f: F, g: G) -> impl Fn(A) -> CExpand description
Composes two functions.
Takes two functions, f and g, and returns a new function that applies g to its argument,
and then applies f to the result. This is equivalent to the mathematical composition f ∘ g.
§Type Signature
forall a b c. (b -> c, a -> b) -> (a -> c)
§Type Parameters
A: The input type of the inner functiong.B: The output type ofgand the input type off.C: The output type of the outer functionf.F: The type of the outer function.G: The type of the inner function.
§Parameters
f: The outer function to apply second.g: The inner function to apply first.
§Returns
A new function that takes an A and returns 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);
// 3 * 2 + 1 = 7
assert_eq!(
times_two_add_one(3),
7
);