Questions/issues regarding generators

Dmitry Lomov dslomov at google.com
Mon Mar 11 23:06:42 PDT 2013


On Mar 12, 2013 6:56 AM, "Jason Orendorff" <jason.orendorff at gmail.com>
wrote:
>
> On Mon, Mar 11, 2013 at 2:48 PM, Kevin Gadd <kevin.gadd at gmail.com> wrote:
>>
>> Another option for scenarios like open() where it is not cheap to
>> create multiple distinct iterators (each starting from the beginning),
>> or for scenarios where it's impossible (like a network stream) would
>> be to only expose an iterator in those instances, not an iterable.
>
>
> But then how would you use it?
>
> If you could not use a for-of loop on it, or pass it to functions like
zip(), that is throwing the baby out with the bathwater.
>

At a risk of repeating myself, 'open()' scenario is handled perfectly well
with the iterable (see my example). Example where things truly cannot be
reiterated (I am not sure why network stream is such an example - the
network connection can always be opened twice) are rare. One possibility
will be to throw on the second call to iterator().

> -j
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130312/3cd95f35/attachment.html>


More information about the es-discuss mailing list