controlling sparseness of Array iterators (was: Array#filter without callback function)
On Mon, Nov 12, 2012 at 5:39 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:
So the question on the floor: is there any interest in having this variation of array iteration in ES6?
I would prefer not. Sparse arrays are really rare and for the few cases these are used I expect the author to be willing to pay a little bit extra instead of everyone else having to pay for these rare cases.
On Nov 12, 2012, at 3:03 PM, Erik Arvidsson wrote:
On Mon, Nov 12, 2012 at 5:39 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote: So the question on the floor: is there any interest in having this variation of array iteration in ES6?
I would prefer not. Sparse arrays are really rare and for the few cases these are used I expect the author to be willing to pay a little bit extra instead of everyone else having to pay for these rare cases.
What's the "everyone else" cost? If you don't request sparseness you get a dense iteration and since this is determined when the iterator is created an implementation can select a minimum cost algorithm.
On Mon, Nov 12, 2012 at 4:39 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:
So the question on the floor: is there any interest in having this variation of array iteration in ES6?
No. Why complicate the API with a feature just for people who use sparse arrays on purpose? From what we hear, there are almost no such people.
this is really easy to fix via code but I would rather propose an Array#compact() or Array#dense() method rather than changing everything else (included shims/polyfills)
I really don't remember when it happened last time that I had to deal with
such kind of Arrays ... and this made already every polyfill slower with
the index in array check per each element in the loop: edge case, a bit
too much, imho, not worth it to include now in every method otherwise we
gonna have all native Array wrappers meanwhile that browsers will catch up,
I can bet that
In the Oct. ES6 draft you may noticed that there is an editor's comment attached to each of sections 15.4.4.23-25. These are the definitions of the items, keys, and values methods on array objects. The note says:"Need to decide whether to allow an argument that requests sparse iteration". In other words, should their signatures be: Array.prototype.items(sparse = false) Array.prototype.keys(sparse = false) Array.prototype.values(sparse = false)
There is also code in the algorithm for ArrayIterator.prototype.next (1415.4.6.2.2) that allow it to conditionally include or exclude sparse elements in any iteration.
I believe that when we last discussed sparseness we concluded that the array iterators would include sparse elements even though the existing map/filter/etc. methods do not.
Adding the above parameter would make both options available, but with dense iteration being the default.
So the question on the floor: is there any interest in having this variation of array iteration in ES6?
In the Oct. ES6 draft you may noticed that there is an editor's comment attached to each of sections 15.4.4.23-25. These are the definitions of the items, keys, and values methods on array objects. The note says:"Need to decide whether to allow an argument that requests sparse iteration". In other words, should their signatures be: Array.prototype.items(sparse = false) Array.prototype.keys(sparse = false) Array.prototype.values(sparse = false) There is also code in the algorithm for ArrayIterator.prototype.next (1415.4.6.2.2) that allow it to conditionally include or exclude sparse elements in any iteration. I believe that when we last discussed sparseness we concluded that the array iterators would include sparse elements even though the existing map/filter/etc. methods do not. Adding the above parameter would make both options available, but with dense iteration being the default. So the question on the floor: is there any interest in having this variation of array iteration in ES6? Allen On Nov 12, 2012, at 1:29 PM, Andrea Giammarchi wrote: > if it's about iterating you have forEach which does not iterate over non assigned indexes ... this looks like you want a new feature with an ES5 method as filter is so that you can use an ES3 for loop after ... > > I mean, you have forEach, map, etc to iterate valid indexes, why would you need that? > > > On Mon, Nov 12, 2012 at 1:24 PM, Asen Bozhilov <asen.bozhilov at gmail.com> wrote: > Hi, > > Array.prototype.filter could be used to convert sparse to dense array, e.g. > > [1,,,,,2,,,,,3].filter(Boolean.bind(null, true)); //[1, 2, 3] > > Would be pretty straightforward if built-in filter could be called without callback function and returns a dense array. > I guess the engines will optimize that and library authors could gracefully iterate over index properties of arrays without checking for existance. > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121112/cdc7b458/attachment.html>