Skip to content

Commit 2c6b6ed

Browse files
bors[bot]fenhl
andauthored
Merge #435
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 <[email protected]>
2 parents e8729dd + 72147c6 commit 2c6b6ed

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,28 @@ pub trait Itertools : Iterator {
26252625
None => Err(ExactlyOneError::new((None, None), self)),
26262626
}
26272627
}
2628+
2629+
/// An iterator adaptor that allows the user to peek at multiple `.next()`
2630+
/// values without advancing the base iterator.
2631+
///
2632+
/// # Examples
2633+
/// ```
2634+
/// use itertools::Itertools;
2635+
///
2636+
/// let mut iter = (0..10).multipeek();
2637+
/// assert_eq!(iter.peek(), Some(&0));
2638+
/// assert_eq!(iter.peek(), Some(&1));
2639+
/// assert_eq!(iter.peek(), Some(&2));
2640+
/// assert_eq!(iter.next(), Some(0));
2641+
/// assert_eq!(iter.peek(), Some(&1));
2642+
/// ```
2643+
#[cfg(feature = "use_std")]
2644+
fn multipeek(self) -> MultiPeek<Self>
2645+
where
2646+
Self: Sized,
2647+
{
2648+
multipeek_impl::multipeek(self)
2649+
}
26282650
}
26292651

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

0 commit comments

Comments
 (0)