Skip to content

Commit

Permalink
Merge #435
Browse files Browse the repository at this point in the history
435: Add multipeek method r=jswrenn a=fenhl

This adds a `multipeek` method to the `Itertools` trait as a more convenient way to use the `multipeek` function.

Co-authored-by: Fenhl <fenhl@fenhl.net>
  • Loading branch information
bors[bot] and fenhl committed Apr 12, 2020
2 parents e8729dd + 72147c6 commit 2c6b6ed
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib.rs
Expand Up @@ -2625,6 +2625,28 @@ pub trait Itertools : Iterator {
None => Err(ExactlyOneError::new((None, None), self)),
}
}

/// An iterator adaptor that allows the user to peek at multiple `.next()`
/// values without advancing the base iterator.
///
/// # Examples
/// ```
/// use itertools::Itertools;
///
/// let mut iter = (0..10).multipeek();
/// assert_eq!(iter.peek(), Some(&0));
/// assert_eq!(iter.peek(), Some(&1));
/// assert_eq!(iter.peek(), Some(&2));
/// assert_eq!(iter.next(), Some(0));
/// assert_eq!(iter.peek(), Some(&1));
/// ```
#[cfg(feature = "use_std")]
fn multipeek(self) -> MultiPeek<Self>
where
Self: Sized,
{
multipeek_impl::multipeek(self)
}
}

impl<T: ?Sized> Itertools for T where T: Iterator { }
Expand Down

0 comments on commit 2c6b6ed

Please sign in to comment.