compose

Function compose 

Source
pub fn compose<'a, ClonableFnBrand: 'a + ClonableFn, A: 'a, B: 'a, C: 'a>(
    f: ApplyFn<'a, ClonableFnBrand, B, C>,
) -> ApplyFn<'a, ClonableFnBrand, ApplyFn<'a, ClonableFnBrand, A, B>, ApplyFn<'a, ClonableFnBrand, A, C>>
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 type B to values of type C.
  • g: A function from values of type A to values of type B.

§Returns

A function from values of type A to values of type C.

§Examples

use fp_library::{brands::RcFnBrand, functions::compose};
use std::rc::Rc;

let add_one = Rc::new(|x: i32| x + 1);
let times_two = Rc::new(|x: i32| x * 2);
let times_two_add_one = compose::<RcFnBrand, _, _, _>(add_one)(times_two);

// 3 * 2 + 1 = 7
assert_eq!(
    times_two_add_one(3),
    7
);