[][src]Function unfold::unfold_count

pub fn unfold_count<T, F>(
    func: F,
    init: T,
    count: usize
) -> impl Iterator<Item = T> where
    F: Fn(T) -> T,
    T: Copy

This function create an unfold iterator that stops at count iterations. Note this is a standard lazy iterator

use unfold::unfold_count;
 
let mut next_odd = unfold_count(|x| x + 2, 1, 3);
assert_eq!(next_odd.next(), Some(1)); 
assert_eq!(next_odd.next(), Some(3)); 
assert_eq!(next_odd.next(), Some(5)); 
assert_eq!(next_odd.next(), None);