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?