[Python-Dev] Rationale behind lazy map/filter
R. David Murray
rdmurray at bitdance.com
Tue Oct 13 11:41:37 EDT 2015
More information about the Python-Dev mailing list
Tue Oct 13 11:41:37 EDT 2015
- Previous message (by thread): [Python-Dev] Rationale behind lazy map/filter
- Next message (by thread): [Python-Dev] Rationale behind lazy map/filter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 13 Oct 2015 11:26:09 -0400, Random832 <random832 at fastmail.com> wrote: > "R. David Murray" <rdmurray at bitdance.com> writes: > > > On Tue, 13 Oct 2015 14:59:56 +0300, Stefan Mihaila > > <stefanmihaila91 at gmail.com> wrote: > >> Maybe it's just python2 habits, but I assume I'm not the only one > >> carelessly thinking that "iterating over an input a second time will > >> result in the same thing as the first time (or raise an error)". > > > > This is the way iterators have always worked. > > It does raise the question though of what working code it would actually > break to have "exhausted" iterators raise an error if you try to iterate > them again rather than silently yield no items. They do raise an error: StopIteration. It's just that the iteration machinery uses that to stop iteration :). And the answer to the question is: lots of code. I've written some: code that iterates an iterator, breaks that loop on a condition, then resumes iterating, breaking that loop on a different condition, and so on, until the iterator is exhausted. If the iterator restarted at the top once it was exhausted, that code would break. --David
- Previous message (by thread): [Python-Dev] Rationale behind lazy map/filter
- Next message (by thread): [Python-Dev] Rationale behind lazy map/filter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list