[Python-Dev] Rationale behind lazy map/filter
R. David Murray
rdmurray at bitdance.com
Tue Oct 13 14:32:10 EDT 2015
More information about the Python-Dev mailing list
Tue Oct 13 14:32:10 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 12:08:12 -0400, Random832 <random832 at fastmail.com> wrote: > "R. David Murray" <rdmurray at bitdance.com> writes: > > On Tue, 13 Oct 2015 11:26:09 -0400, Random832 <random832 at fastmail.com> wrote: > > > > 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 > > I'm not suggesting restarting at the top (I've elsewhere suggested that > many such methods would be better as an *iterable* that can be restarted > at the top by calling iter() multiple times, but that's not the same > thing). I'm suggesting raising an exception other than StopIteration, so > that this situation can be detected. If you are writing code that tries > to resume iterating after the iterator has been exhausted, I have to > ask: why? Because the those second &c loops don't run if the iterator is already exhausted, the else clause is executed instead (or nothing happens, depending on the code). Now, likely such code isn't common (so I shouldn't have said "lots"), but the fact that I've done it at least once, maybe twice (but I can't remember what context, it was a while ago), argues it isn't vanishingly uncommon. --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