Function iterate
fn iterate<St, F>(initial_value: St, f: F) -> Iterate<St, F>
where
F: FnMut(&St) -> St
Creates a new iterator that infinitely applies function to value and yields results.
use iterate;
assert_equal;
Panics if compute the next value does.
# use itertools::iterate;
let mut it = iterate(25u32, |x| x - 10).take_while(|&x| x > 10);
assert_eq!(it.next(), Some(25)); // `Iterate` holds 15.
assert_eq!(it.next(), Some(15)); // `Iterate` holds 5.
it.next(); // `5 - 10` overflows.
You can alternatively use core::iter::successors as it better describes a finite iterator.