compose

Function compose 

Source
pub fn compose<A, B, C, F, G>(f: F, g: G) -> impl Fn(A) -> C
where F: Fn(B) -> C, G: Fn(A) -> B,
Expand description

Backward composition of two functions.

§Arguments

  • f - A function that takes a value in B and returns a value in C
  • g - A function that takes a value in A and returns a value in B

§Returns

A new function that takes a value in A and returns a value in C

§Example

use overture_core::compose::compose;

let add_one = |x: i32| x + 1;
let multiply_by_two = |x: i32| x * 2;
let composed = compose(multiply_by_two, add_one);

assert_eq!(composed(5), 12); // (5 + 1) * 2 = 12