File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -2148,6 +2148,27 @@ where
2148
2148
2149
2149
Ok ( self . next . as_ref ( ) )
2150
2150
}
2151
+
2152
+ /// Consume and return the next value of this iterator if a condition is true.
2153
+ ///
2154
+ /// If func returns true for the next value of this iterator, consume and return it. Otherwise, return None.
2155
+ #[ inline]
2156
+ pub fn next_if ( & mut self , f : impl Fn ( & I :: Item ) -> bool ) -> Result < Option < I :: Item > , I :: Error > {
2157
+ match self . peek ( ) ? {
2158
+ Some ( item) if f ( item) => self . next ( ) ,
2159
+ _ => Ok ( None ) ,
2160
+ }
2161
+ }
2162
+
2163
+ /// Consume and return the next item if it is equal to `expected`.
2164
+ #[ inline]
2165
+ pub fn next_if_eq < T > ( & mut self , expected : & T ) -> Result < Option < I :: Item > , I :: Error >
2166
+ where
2167
+ T : ?Sized ,
2168
+ I :: Item : PartialEq < T > ,
2169
+ {
2170
+ self . next_if ( |found| found == expected)
2171
+ }
2151
2172
}
2152
2173
2153
2174
impl < I > FallibleIterator for Peekable < I >
You can’t perform that action at this time.
0 commit comments