Array comprehensions with Spread operator
Tab Atkins Jr.
jackalmage at gmail.com
Wed Apr 15 16:31:40 UTC 2015
On Wed, Apr 15, 2015 at 9:23 AM, monolithed <monolithed at gmail.com> wrote:
> let x = [0, 1, 2];
> let y = [3, 4, 5];
> // Expected
> [ for (i of [x, y]) ...i ];
> // Reality
> Array.prototype.concat(...[ for (x of [x, y]) i ]);
> // Result
> [0, 1, 2, 3, 4, 5]
> Is there any discussion on this subject?
+1. Right now you can insert 1 (default) or 0 (with a filter) elements
per iteration, but you can't insert 2+. This lack in Python has
forced me to unwrap several comprehensions into explicit loops, which
The general solution to this is monadic, which has been inconclusively
discussed in the past, but the use of the spread operator for this
case is very compelling, imo. It feels *natural*.
More information about the es-discuss