Does it work? For what categories of iterators? Surely not for streams...

--Guido (mobile)

On Jul 23, 2016 4:49 PM, "Chris Angelico" <> wrote:
On Sun, Jul 24, 2016 at 2:57 AM, Serhiy Storchaka <> wrote:
> On 22.07.16 18:48, Chris Angelico wrote:
>> On Sat, Jul 23, 2016 at 12:20 AM, Daniel Moisset
>> <> wrote:
>>> Would there be interest in some kind of method/API for restarting
>>> iterators?
>>> If there was a it.restart() (or reset(it)), it would probably be a good
>>> idea
>>> to name the concept in the same way as the method ( "Restartable" or
>>> "Resettable"). And having that as an actual protocol would simplify the
>>> discussion on both what the type should contain and how it should be
>>> named,
>>> while having actal applications to simplify code (and reduce memory usage
>>> in
>>> cases when creating a list is not needed, just making multiple passes).
>> IMO, no. Some iterators can be restarted by going back to the original
>> iterable and requesting another iterator, but with no guarantee that
>> it will result in the exact same sequence (eg dict/set iterators).
>> Does that count as restarting? And what if you start by consuming a
>> header or two, then pass the resulting iterator to another function.
>> Based on type, it would be restartable (say it's a list_iterator), but
>> the called function would be highly surprised to suddenly get back
>> more results.
>> What you might be looking at is a protocol for "bookmarking" or
>> "forking" an iterator. That might be more useful.
> There is such a protocol. Use copy.copy().

Time machine strikes again! Restarting of iterators exists.

Python-ideas mailing list
Code of Conduct: