See formal spec WIP.
See proposal extending Set and Map with Array-like methods.
This proposal does not change syntax of language.
New methods based on set theory are added to Set.prototype
.
Set.prototype.intersection(iterable)
- method creates newSet
instance by set intersection operation.Set.prototype.union(iterable)
- method creates newSet
instance by set union operation.Set.prototype.difference(iterable)
- method creates newSet
without elements present initerable
.Set.prototype.symmetricDifference(iterable)
- returnsSet
of elements found only in eitherthis
or initerable
.Set.prototype.isSubsetOf(iterable)
Set.prototype.isDisjointFrom(iterable)
Set.prototype.isSupersetOf(iterable)
- 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
Set<T>
- reduces boilerplate code when dealing with common use cases of
Set
- 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)
- No static
intersection
,union
methods in this proposal union
,intersection
,difference
takes single argument
See other languages document to get overview of Set
methods in other languages.
- Static
Set.union(...iterables)
,Set.intersection(...iterables)
See naming bikeshedding document for details.
We decided to choose:
- Symmetric difference -
symmetricDifference
- Intersection -
intersection
- Union -
union
- Difference -
difference