itertools icon indicating copy to clipboard operation
itertools copied to clipboard

Implement `PeekingNext` for `PeekingTakeWhile`.

Open olson-sean-k opened this issue 3 years ago • 0 comments

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).

olson-sean-k avatar Sep 12 '22 21:09 olson-sean-k