You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an iterator that allows mapping with (next_item, Option(&peek_item). This is useful for parsers. Exact semantics may vary, but the goal is to get something like tuple_windows without needing to clone
100% credit to @talchas on Discord (I don't see that user here) for the implementation:
use std::iter::Peekable;pubstructPeekMap<I:Iterator,F>(Peekable<I>,F);pubfnpeek_map<R,I:Iterator,F:FnMut(I::Item,Option<&I::Item>) -> R>(it:Peekable<I>,f:F) -> PeekMap<I,F>{PeekMap(it, f)}impl<R,I:Iterator,F:FnMut(I::Item,Option<&I::Item>) -> R>IteratorforPeekMap<I,F>{typeItem = R;fnnext(&mutself) -> Option<R>{let x = self.0.next()?;Some((self.1)(x,self.0.peek()))}}
The text was updated successfully, but these errors were encountered:
Add an iterator that allows mapping with
(next_item, Option(&peek_item)
. This is useful for parsers. Exact semantics may vary, but the goal is to get something liketuple_windows
without needing to clone100% credit to @talchas on Discord (I don't see that user here) for the implementation:
The text was updated successfully, but these errors were encountered: