Function streaming_iterator::successors [−][src]
pub fn successors<T, F: FnMut(T) -> Option<T>>(
first: Option<T>,
succ: F
) -> Successors<T, F>
Creates an iterator where each successive item is computed from the preceding one.
let mut streaming_iter = streaming_iterator::successors( Some(1), |count| if count < 3 { Some(count + 1) } else { None }, ); assert_eq!(streaming_iter.next(), Some(&1)); assert_eq!(streaming_iter.next(), Some(&2)); assert_eq!(streaming_iter.next(), Some(&3)); assert_eq!(streaming_iter.next(), None);