<p dir="ltr">Does it work? For what categories of iterators? Surely not for streams...</p>
<p dir="ltr">--Guido (mobile)</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Jul 23, 2016 4:49 PM, "Chris Angelico" <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Jul 24, 2016 at 2:57 AM, Serhiy Storchaka <<a href="mailto:storchaka@gmail.com">storchaka@gmail.com</a>> wrote:<br>
> On 22.07.16 18:48, Chris Angelico wrote:<br>
>><br>
>> On Sat, Jul 23, 2016 at 12:20 AM, Daniel Moisset<br>
>> <<a href="mailto:dmoisset@machinalis.com">dmoisset@machinalis.com</a>> wrote:<br>
>>><br>
>>> Would there be interest in some kind of method/API for restarting<br>
>>> iterators?<br>
>>> If there was a it.restart() (or reset(it)), it would probably be a good<br>
>>> idea<br>
>>> to name the concept in the same way as the method ( "Restartable" or<br>
>>> "Resettable"). And having that as an actual protocol would simplify the<br>
>>> discussion on both what the type should contain and how it should be<br>
>>> named,<br>
>>> while having actal applications to simplify code (and reduce memory usage<br>
>>> in<br>
>>> cases when creating a list is not needed, just making multiple passes).<br>
>><br>
>><br>
>> IMO, no. Some iterators can be restarted by going back to the original<br>
>> iterable and requesting another iterator, but with no guarantee that<br>
>> it will result in the exact same sequence (eg dict/set iterators).<br>
>> Does that count as restarting? And what if you start by consuming a<br>
>> header or two, then pass the resulting iterator to another function.<br>
>> Based on type, it would be restartable (say it's a list_iterator), but<br>
>> the called function would be highly surprised to suddenly get back<br>
>> more results.<br>
>><br>
>> What you might be looking at is a protocol for "bookmarking" or<br>
>> "forking" an iterator. That might be more useful.<br>
><br>
><br>
> There is such a protocol. Use copy.copy().<br>
<br>
Time machine strikes again! Restarting of iterators exists.<br>
<br>
ChrisA<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div>