Function sknife::collection::reduce [] [src]

pub fn reduce<F, A>(reduce_fn: F, vect: &mut [A], initial: A) -> A where
    F: FnMut(A, A) -> A,
    A: Clone

Reduce a vector/list using an accumulating function

Arguments

  • vect - A vector to apply the map to
  • reduce_fn - Accumulating function to apply to the list
  • initial - An initial value to accumulate upon

Example

use sknife::collection::reduce;
let initial = 1;
let mut list = vec![1, 2, 3];
let fact = |acc, x| acc * x;
reduce(fact, list.as_mut_slice(), initial);
 

Result

6;