Destructuring of generators

Kevin Smith zenparsing at
Sun May 25 13:24:56 PDT 2014

> I’m not sure thats a good idea in case of generators. Of course one can
> easily work around that by doing `[a, b] = gen; rest = gen;`. But that
> takes away half the sweetness of the sugar :-) And the lazyness.
> And you can’t use that pattern inside parameters.

The rest element needs to evaluate to the same kind of thing, whether the
destructured object is a generator iterator or otherwise.  Given all the
other factors, having the rest element evaluate to an array makes the most
sense to me.

Besides, it really doesn't seem that annoying to simply capture the
iterator in question before destructuring it.

    var iter = myGenerator(), [a, b] = iter;

    function f(iter) { var [a, b] = iter; }

But if so, perhaps a future syntax addition could address that.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list