Set some, every, reduce, filter, map methods

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Set some, every, reduce, filter, map methods

Peter Michaux
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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Set some, every, reduce, filter, map methods

Herby Vojčík
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
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Set some, every, reduce, filter, map methods

Erik Arvidsson
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.

On Mar 30, 2013 8:06 AM, "Herby Vojčík" <[hidden email]> 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
>> [hidden email]
>> https://mail.mozilla.org/listinfo/es-discuss
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Set some, every, reduce, filter, map methods

Herby Vojčík
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

> 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.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Set some, every, reduce, filter, map methods

Rick Waldron
In reply to this post by Erik Arvidsson


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" <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;herby@mailbox.sk&#39;)">herby@...> 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
>> <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;es-discuss@mozilla.org&#39;)">es-discuss@...
>> https://mail.mozilla.org/listinfo/es-discuss
>
> _______________________________________________
> es-discuss mailing list
> <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;es-discuss@mozilla.org&#39;)">es-discuss@...
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;es-discuss@mozilla.org&#39;)">es-discuss@...
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Set some, every, reduce, filter, map methods

Peter Michaux
In reply to this post by Herby Vojčík
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

On Sat, Mar 30, 2013 at 5:06 AM, Herby Vojčík <[hidden email]> 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
>> [hidden email]
>> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss