Trait grabbag::iter::AccumulateIterator [] [src]

pub trait AccumulateIterator<E>: Iterator<Item=E> + Sized {
    fn accumulate<F: FnMut(E, E) -> E>(self, f: F) -> Accumulate<Self, E, F> { ... }
}

( a0, a1, a2, ... ), ⊗  →  ( a0, (a0a1), ((a0a1) ⊗ a2), ... )

Provided Methods

fn accumulate<F: FnMut(E, E) -> E>(self, f: F) -> Accumulate<Self, E, F>

Creates an iterator that scans from left to right over the input sequence, returning the accumulated result of calling the provided function on the entire sequence up to that point.

Example

let v = vec![0usize, 1, 2, 3, 4];

// `r` is the sequence of partial sums of `v`.
let r: Vec<_> = v.into_iter().accumulate(|a,b| a+b).collect();
assert_eq!(r, vec![0, 1, 3, 6, 10]);

Implementors