Re: `.toArray()` for all generators

2013-08-29 Thread Andreas Rossberg
On 28 August 2013 17:02, Forbes Lindesay for...@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

RE: `.toArray()` for all generators

2013-08-29 Thread Forbes Lindesay
To: Forbes Lindesay Cc: es-discuss@mozilla.org Subject: Re: `.toArray()` for all generators On 28 August 2013 17:02, Forbes Lindesay for...@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

Re: `.toArray()` for all generators

2013-08-29 Thread Andrea Giammarchi
: Andreas Rossberg [mailto:rossb...@google.com] Sent: 29 August 2013 09:56 To: Forbes Lindesay Cc: es-discuss@mozilla.org Subject: Re: `.toArray()` for all generators On 28 August 2013 17:02, Forbes Lindesay for...@lindesay.co.uk wrote: It would be nice from a readability point of view

`.toArray()` for all generators

2013-08-28 Thread Forbes Lindesay
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

Re: `.toArray()` for all generators

2013-08-28 Thread Axel Rauschmayer
On Aug 28, 2013, at 17:02 , Forbes Lindesay for...@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? For me, [ ... iterable ]

RE: `.toArray()` for all generators

2013-08-28 Thread Forbes Lindesay
The thing about `.map` and `.filter` is that it would be easy enough to create functional versions: ```js function* map(array, fn) { for (var x of array) { yield fn(x) } } ``` But harder to create methods: ```js Iteratable.prototype.map = function(fn) { for (var x of this) {

Re: `.toArray()` for all generators

2013-08-28 Thread Claude Pache
Note that an equivalent of both `.map` and `.filter` already exists in ES6: its name is generator expression. For instance: ``` array.filter(pred).map(transf) ``` becomes: ``` (for (let x of iter) if (pred(x)) transf(x)) ``` —Claude Le 28 août 2013 à 17:27, Forbes Lindesay

Re: `.toArray()` for all generators

2013-08-28 Thread Rick Waldron
On Wed, Aug 28, 2013 at 11:02 AM, Forbes Lindesay for...@lindesay.co.ukwrote: It would be nice from a readability point of view if `iteratable.toArray()` could always be used as a substitute for `Array.from(iteratable)`. Since both Array.from and [..spread] already covers every single

Re: `.toArray()` for all generators

2013-08-28 Thread Andrea Giammarchi
I completely agree with Rick plus this is what I meant in the other thread when I've said I don't see the urge/need to deal with Iterators = Arrays if not ending up with waste of resources as the one proposed here. Somebody will need to write specs, tests, and implementations while we have all