Destructuring of generators

Arpad Borsos arpad.borsos at
Sun May 25 05:21:20 PDT 2014

The destructuring assignment of the form
`[a, b,] = x` accepts any kind of iterator.
Which is great.

However, IteratorDestructuringAssignmentEvaluation of
AssignmentRestElement is defined such that it creates a new Array and
completely walks the iterator until its exhausted.

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.

Also, there is the obvious problem what happens if you pass an
infinite generator.

Any ideas?

More information about the es-discuss mailing list