Name: proposal-set-methods
Owner: Ecma TC39
Description: Strawman for new Set methods
Created: 2016-05-28 16:40:47.0
Updated: 2018-05-23 21:26:23.0
Pushed: 2018-05-22 20:27:40.0
Homepage: https://tc39.github.io/proposal-set-methods/
Size: 84
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
See formal spec WIP.
See proposal extending Set and Map with Array-like methods.
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
intersection
, union
methods in this proposalunion
, intersection
, difference
takes single argumentJava Set
interface is rather limited and doesn't include APIs found in this proposal.
Though, Java 8 introduces stream API that allow to deal with arbitrary collections.
Stream API has methods from this proposal like union
(as concat
).
Stream API nor Set
does not include intersection
, xor
.
.union
, .intersection
etc. desired signatureSignature of these functions isn't obvious. They can accept:
.intersect
method)Set
instances (intersection
without at least log(n)
random access seems to be too slow for real world)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 new Set
instance by set intersection operation.Set.prototype.union(iterable)
- method creates new Set
instance by set union operation.Set.prototype.difference(iterable)
- method creates new Set
without elements present in iterable
.Set.prototype.symmetricDifference(iterable)
- returns Set
of elements found only in either this
or in iterable
.Set.prototype.isSubsetOf(otherSet)
Set.prototype.isSupersetOf(iterable)
Set.union(...iterables)
, Set.intersection(...iterables)
Symmetric difference
Proposed names: xor
, symmetricDifference
, disjointUnion
Intersection
Proposed names: intersect
, intersection
.
Union
Proposed names: union
, concat
.
Difference
Proposed names: difference
, minus
, except
, without
, withoutAll
, relativeComplement
.