Set some, every, reduce, filter, map methods
Definitely, +1.
Also, add reduceRight as well, even if it would only do the same as reduce.
I said this in the other thread but I don't mind repeating myself. A better way forward is to provide these for iterators.
mySet.values().some(func) mySet.values().every(func) mySet.values().reduce(func) new Set(mySet.values().filter(func)) new Set(mySet.values().map(func))
I'm not opposed to adding these to Set and Map but I think it is more important to define these using iterators first since it scales better to new collection types.
Well, why not, but forEach, some, every, reduce[Right] and filter are very natural operations useful for any collection (map is harder). If Set has forEach, it should have these as well. Of course, iterators could have them as well.
It is strange if Array and iterators would have it, but other collections would not. The code that takes a collection as a parameter and calls some, every, filter etc. on it would break, instead of doing the job on Set (at least some, every and reduce family can be transparently used; and I would argue for filter as well - it returns subcollection that understands the collection protocol (@@iterator, values, forEach, some, every, filter, reduce, reduceRight)).
Herby
P.S.: What should generic collection contract consist of in ES6? I would say the except those named above only needed addition is isEmpty, length/size, and possibly clear as well as copy/clone (slice is not right for Set/Map).
Erik Arvidsson wrote:
I said this in the other thre
ad but I don't mind repeating myself. A
On Saturday, March 30, 2013, Erik Arvidsson wrote:
I said this in the other thread but I don't mind repeating myself. A better way forward is to provide these for iterators.
mySet.values().some(func) mySet.values().every(func) mySet.values().reduce(func) new Set(mySet.values().filter(func)) new Set(mySet.values().map(func))
My intention is not to refute the above, but these methods can be used by spreading the iterable set into an array:
[...mySet].some(func)
Of course this has allocation costs...
Rick
I'm not opposed to adding these to Set and Map but I think it is more important to define these using iterators first since it scales better to new collection types.
On Mar 30, 2013 8:06 AM, "Herby Voj??k" <herby at mailbox.sk <javascript:;>> wrote:
Definitely, +1.
Also, add reduceRight as well, even if it would only do the same as reduce.
Peter Michaux wrote:
In another thread, I'm told there is currently no plans to add the following to Set.prototype.
some every reduce filter map
These seem like very natural additions and the type of operations that one would want to do on sets.
Peter
es-discuss mailing list es-discuss at mozilla.org <javascript:;> mail.mozilla.org/listinfo/es-discuss
es-discuss mailing list es-discuss at mozilla.org <javascript:;> mail.mozilla.org/listinfo/es-discuss
es-discuss mailing list es-discuss at mozilla.org <javascript:;> mail.mozilla.org/listinfo/es-discuss
-------------- next part -------------- An HTML attachment was scrubbed... URL: esdiscuss/attachments/20130330/c63e9c2e/attachment
The order of iteration of a set is the order of insertion of elements into the set. So reduce and reduceRight would actually be different. I should have included reduceRight in my list.
Peter
In another thread, I'm told there is currently no plans to add the following to Set.prototype.
some every reduce filter map
These seem like very natural additions and the type of operations that one would want to do on sets.
Peter