Re: Why can’t for-of be applied to iterators?

Jason Orendorff jason.orendorff at gmail.com
Tue Jun 11 06:42:10 PDT 2013


On Tue, Jun 11, 2013 at 4:34 AM, Andy Wingo <wingo at igalia.com> wrote:

> So, my proposal would be to make the for-of RHS expect an iterator, and
> remove the concept of "iterable".  So there's no need to check for
> anything; you just assume you have an iterator.
>
> I don't find the cost of this change (let's not say "tax" ;) terrible:
>
>   for (x of y.values()) f(x);
>

I can see the tradeoffs between a tax on the performance of loops and a tax
on people who want to implement iterators without using generators (hint:
use a generator). But a tax on everyone who wants to write a loop seems
clearly much worse.

As iterators and for-of become more prevelant, I think there are
> actually few times that you want the default iterator -- the reason
> being that you will deal more with iterators and less with reified
> containers like arrays.  The evolution of Python seems to show this, and
> (dare I mention it?) Dart also seems to be going in this direction.
>

I can't speak for Dart, but the evolution of Python shows no such thing.

Please look at any Python codebase. The right-hand side of a for loop is
most often just an identifier or simple expression naming a collection. You
will see a few calls to enumerate(), .items(), and so on, but they do not
predominate. Sometimes it's a list literal.

I will quantify this later today.

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130611/6d686852/attachment.html>


More information about the es-discuss mailing list