`.toArray()` for all generators

Forbes Lindesay forbes at lindesay.co.uk
Thu Aug 29 09:01:01 PDT 2013

This all seems fair enough.  My concern is mostly that the `blob.method(fn)` syntax seems much easier to get your head around (as someone familiar to JavaScript) than the `[for (let x of iter) if (pred(x) transf(x)]`.  I always used the traditional syntax for LINQ in C# as well (which gave you both options).  Perhaps I'm just too set in my ways though.  I'm happy to accept that it's probably easy enough to just rely on `Array.from` when you want an array from an iterator.

-----Original Message-----
From: Andreas Rossberg [mailto:rossberg at google.com] 
Sent: 29 August 2013 09:56
To: Forbes Lindesay
Cc: es-discuss at mozilla.org
Subject: Re: `.toArray()` for all generators

On 28 August 2013 17:02, Forbes Lindesay <forbes at lindesay.co.uk> wrote:
> It would be nice from a readability point of view if 
> `iteratable.toArray()` could always be used as a substitute for 
> `Array.from(iteratable)`.  Is there a way that could be neatly 
> achieved?  It would also be nice if methods like `.map` and `.filter` 
> existed on iteratables.  C# does this via the concept of extension 
> methods, but I wonder whether something similar could be achieved here, at least in the case of built in iteratables?

In addition to what others have already said, note that iterators model streams that are not necessarily finite. Hence, a toArray method would not generally be well-defined.


More information about the es-discuss mailing list