Closed dead-claudia closed 5 years ago
I need set.map(func) -> set
too often and I don't remember any use case of set.map(func) -> iterator
. If you need it, use set.values().map(func) -> iterator
from this proposal.
Virtually every use case for mapping over an array applies to a Set, and vice versa.
If you’re asking about whether it should return an iterator instead of reifying a new Set, that question applies to every method in this proposal, and the answer is “methods on X typically produce a new X”. The iterator helpers proposal seems like it’d be what you want.
@ljharb @zloirock
I'm familiar with the iterator helpers proposal, and that's precisely why I was asking what the use case for set.map
was. I've not encountered a single scenario, either in my own code or anyone else's I've read, where this was actually useful.
[@ljharb:] Virtually every use case for mapping over an array applies to a Set, and vice versa.
I can see this in the abstract, but what does this mean concretely?
[@zloirock:] I need
set.map(func) -> set
too often
Could you give me examples of when you need this?
For example, I need to do something with a collection (for example, extract property from an object), store the result and use .has
method with O(1)
complexity on it. At least 3 cases for 2 previous days.
So the new Set(set.values().map(...))
(borrowing from the iterator helpers) is common enough to warrant inclusion? If so, I'll go ahead and close this issue.
Even if we had iterator helpers first, imo we'd still want .map
on arrays - the existence of a generic solution doesn't preclude the usefulness of a specific one.
I'm having a tough time figuring out what a
set.map(func) -> set
is for. I could see value in aset.map(func) -> iterator
inherited from an %IterablePrototype% as it makes no sense to special case it there, but I'm not sure how useful a standalone, deduplicatingset.map(func) -> set
would be.