New Set methods
See formal spec WIP.
This proposal does not change syntax of language.
New methods based on set theory are added to
Set.prototype.intersection(iterable)- method creates new
Setinstance by set intersection operation.
Set.prototype.union(iterable)- method creates new
Setinstance by set union operation.
Set.prototype.difference(iterable)- method creates new
Setwithout elements present in
Setof elements found only in either
(Semi)relevant previous discussions
- Map#map and Map#filter
- Map.prototype.map and Map.prototype.filter (spec) + Set
- Map: filter/map and more
- Original topic regarding this proposal
- Newer topic regarding this proposal
- reduces need to depend on Immutable.js
- reduces boilerplate code when dealing with common use cases of
- no new syntax
- No npm package duplicating this proposal was found
- Very similar API was found in popular Collections.js (205k downloads per month)
- This proposal is inspired by Set API from Immutable.js (3M downloads per month)
Comparision with Immutable.js
- No static
unionmethods in this proposal
differencetakes single argument
Comparison with other languages
See other languages document to get overview of
Set methods in other languages.
Not included in this proposal but worth considering
See naming bikeshedding document for details.
We decided to choose:
- Symmetric difference -
- Intersection -
- Union -
- Difference -