-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why not .reduce
?
#3
Comments
From @domenic on January 16, 2018 1:42 reduce() is currently included. However, it's a bit strange as it assumes an ordering, which JS sets have, but is not part of the usual concept of a set. reduceRight() is missing though. I think either neither or both should be included. |
From @pitaj on January 16, 2018 1:47 In my opinion, not having reduce makes more sense, as there's no way to sort a set. As you said, sets don't normally have an order. I think doing |
I understand your concerns about Personally I would like to make set iteration implementation-dependent but guaranteed to be stable. |
From @domenic on January 19, 2018 18:0 OK, so why doesn't indexOf(el) exist then? It would tell you what position in iteration order the element appears. |
Because sets aren't indexable, so it would be virtually useless (though, Python provide generic Conceptually, position in iteration order shouldn't even matter. And there are many use cases where starting item for |
From @domenic on January 20, 2018 0:50 I don't find the comparison convincing. Calling If position in iteration order shouldn't matter, then please don't add reduce(), as it's entirely built on that idea. It would indeed be a different story if we had a language with some way to enforce associative-only operations, but we don't, so iteration order is an intrinsic part of the reduce method. |
From @pitaj on January 20, 2018 1:8 It's also worth mentioning that for most associative operations, like |
From @tabatkins on January 23, 2018 22:13
Strongly disagree. As you note in the following (unquoted) sentence, reduce() on a set completely makes sense if you have commutative+associative reducers, but in reality sets are ordered on the web platform (note that Infra only defines ordered sets for exactly this reason), and so arbitrary reducers make sense just fine. I do agree that I'm ambivalent on |
From @pitaj on January 23, 2018 22:22 We need to decide if the implicit insertion-ordering of Set qualifies as Array-like ordered behavior. If it does, then |
I'm actually having a hard time coming up with an example case for reduce where I would care about the order. In most cases that make sense to use reduce for, I think it unlikely that the order will be meaningful. Perhaps something like Honestly the best argument I can think of for not having this, is that it's questionable that arrays have it in the first place. There are few and far between uses for |
From @pitaj on July 31, 2017 2:0
There may be few use cases for reduce on a set, but they do exist. It would serve as extra consistency with Arrays as well.
Copied from original issue: tc39/proposal-set-methods#3
The text was updated successfully, but these errors were encountered: