Clone or download
Latest commit df45c80 Jan 9, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Closes #27 Jan 9, 2019
spec Closes #27 Jan 9, 2019
test/set 'New' proposal Jan 27, 2018
.gitignore add `Map.prototype.{some, every}` Jul 3, 2018
LICENSE Minor fix for links/typos Jan 31, 2018 Fixes #21 Jan 9, 2019
map-polyfill.js 'New' proposal Jan 27, 2018
package-lock.json Fixed vuln. dependencies Jul 3, 2018
package.json Fixed vuln. dependencies Jul 3, 2018
set-polyfill.js 'New' proposal Jan 27, 2018

New collections (Set and Map) methods

See formal spec WIP.

(Semi)relevant previous discussions


  • it's consistent with already familiar and widely used Array API (reduced cognitive overhead)
    • easier refactoring
    • certain function become generic
  • reduces boilerplate code when dealing with common collection use cases
  • no new syntax
  • allow developers coming from other languages to use familiar APIs



Quick reference for other languages similar data structures


Map (known also as Dictionary)



This proposal does not change grammar of language.

New methods are added to Set.prototype.

  • Array-like methods. These methods replicates functionality of Array.prototype methods:
    • Set.prototype.filter(predicate, thisArg)
    •, thisArg)
    • Set.prototype.find(fn, thisArg)
    • Set.prototype.reduce(fn, initialValue)
    • Set.prototype.join(separator)
    • Set.prototype.some(predicate, thisArg)
    • Set.prototype.every(predicate, thisArg)
  • New methods:
    • Set.prototype.addAll(...elements) - similar to Array.prototype.push. Adds all of arguments to existing Set.
      • Alternative name: .addEach
    • Set.prototype.deleteAll(...elements) - reverse of addAll. Remove every element in elements from existing Set.
      • Alternative names: .deleteEach

New methods are added to Map.prototype.

  • Array-like methods. These methods replicates functionality of Array.prototype methods:

    • Map.prototype.filter(predicate, thisArg)
    • Map.prototype.mapValues(fn, thisArg)
    • Map.prototype.mapKeys(fn, thisArg)
    • Map.prototype.reduce(fn, initialValue)
    • Map.prototype.find(fn, thisArg)
    • Map.prototype.findKey(fn, thisArg)
    • Map.prototype.keyOf(searchElement)
    • Map.prototype.some(predicate, thisArg)
    • Map.prototype.every(predicate, thisArg)
    • Map.prototype.includes(searchElement)
  • New methods:

    • Map.prototype.deleteAll(...elements) - similar to Set.prototype.deleteAll.
    • Map.prototype.merge(...iterables) - performs in-place update joining arbitrary number of iterables.

New methods are added to %Map%.

  • Map.groupBy(iterable, keyDerivative) -
  • Map.keyBy(iterable, keyDerivative) -

New methods are added to WeakSet.prototype.

  • New methods:
    • WeakSet.prototype.addAll(...elements) - similar to Set.prototype.addAll.
    • WeakSet.prototype.deleteAll(...elements) - similar to Set.prototype.deleteAll.

New methods are added to WeakMap.prototype.

  • New methods:
    • WeakMap.prototype.deleteAll(...elements) - similar to Map.prototype.deleteAll.

Not included in this proposal but worth considering

Why not %IteratorPrototype% methods

  • Explicit usage of iterators is verbose
    • Compare new Set(set.entries().filter(fn)) to set.filter(fn). 19 characters of boilerplate.
      • Even small codebase can have hundreds occurrences of this pattern - and hundreds places to make a mistake.
  • User code have no easy way to inherit from %IteratorPrototype%