Function rust2fun::combinator::converge

source ·
pub fn converge<A: Copy, B, C, D, F, G, H>(f: F, g: G, h: H, x: A) -> Dwhere
    F: FnOnce(B, C) -> D,
    G: FnOnce(A) -> B,
    H: FnOnce(A) -> C,
Expand description

Provides a means of passing an accumulating function and two branching functions. A value can be applied to the resulting function which will then be applied to each branching function, the results of which will be applied to the accumulating function.

Example

use rust2fun::prelude::*;

let divide = |x: u32, y: usize| x / (y as u32);
let sum = |x: &Vec<u32>| x.iter().sum();
let actual = converge(divide, sum, Vec::len, &vec![1, 2, 3]);
assert_eq!(2, actual);