We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a948086 commit 6d39221Copy full SHA for 6d39221
src/peek_nth.rs
@@ -115,6 +115,23 @@ where
115
116
self.buf.get_mut(n)
117
}
118
+
119
+ /// Works exactly like the `next_if` method in `std::iter::Peekable`
120
+ pub fn next_if(&mut self, func: impl FnOnce(&I::Item) -> bool) -> Option<I::Item> {
121
+ match self.peek() {
122
+ Some(m) if func(&m) => self.next(),
123
+ _ => None,
124
+ }
125
126
127
+ /// Works exactly like the `next_if_eq` method in `std::iter::Peekable`
128
+ pub fn next_if_eq<T>(&mut self, expected: &T) -> Option<I::Item>
129
+ where
130
+ T: ?Sized,
131
+ I::Item: PartialEq<T>,
132
+ {
133
+ self.next_if(|next| next == expected)
134
135
136
137
impl<I> Iterator for PeekNth<I>
0 commit comments