[Python-Dev] Rationale behind lazy map/filter

Chris Jerdonek chris.jerdonek at gmail.com
Tue Oct 13 13:44:02 EDT 2015


On Tue, Oct 13, 2015 at 8:26 AM, 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.

What about cases where not all of the elements of the iterator are
known at the outset?  For example, you might have a collection of
pending tasks that you periodically loop through and process.
Changing the behavior would result in an error when checking for more
tasks instead of no tasks.

--Chris


More information about the Python-Dev mailing list