pub fn from_fn<T, F: FnMut() -> Option<T>>(gen: F) -> FromFn<T, F>
Expand description

Creates an iterator that returns items from a function call.

let mut count = 0;
let mut streaming_iter = streaming_iterator::from_fn(|| {
    count += 1;
    if count < 4 { Some(count) } 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);