itertools
itertools copied to clipboard
Implement `PeekingNext` for `PeekingTakeWhile`.
This PR implements PeekingNext for PeekingTakeWhile by composing its predicate with the predicate given to PeekingNext::peeking_next. This allows Itertools::peeking_take_while to be chained and for subsequent calls, including those across function boundaries, to function as expected while restoring items in the originating iterator.
See also #643, which implements PeekingNext for mutable references. In combination, these changes allow code to generically accept types implementing PeekingNext where Itertools::peeking_take_while can be used by the caller to prepare an iterator and subsequently by a function where restoring items in the originating iterator is important (i.e., the function cannot simply use Iterator::peekable etc., because Iterator::next would unconditionally be called on the originating iterator).