pub fn multipeek<I>(iterable: I) -> MultiPeek<I::IntoIter>Notable traits for MultiPeek<I>impl<I> Iterator for MultiPeek<I> where
    I: Iterator
type Item = I::Item;
where
    I: IntoIterator
Expand description

An iterator adapter to peek at future elements without advancing the cursor of the underlying iterator.

See MultiPeek::peek() and MultiPeek::peek_nth() for more details.

Example

use multipeek::multipeek;

let mut iter = multipeek([1, 2, 3, 4].into_iter());

// Peek at the first element.
let first_peek = iter.peek().cloned();
assert_eq!(first_peek, Some(1));

// Advance the iterator cursor to point at the first element.
let first = iter.next();
assert_eq!(first, first_peek);

// Peek two steps ahead, at the third element.
let third_peek = iter.peek_nth(1).cloned();
assert_eq!(third_peek, Some(3));

// Advance the iterator cursor twice. The iterator cursor will now point to the third element.
iter.next();
let third = iter.next();
assert_eq!(third_peek, third);

// Peeking beyond the end of the iterator returns `None`.
let ambitious_peek = iter.peek_nth(5);
assert!(ambitious_peek.is_none());