tc39 / proposal-upsert

ECMAScript Proposal, specs, and reference implementation for Map.prototype.upsert
https://tc39.es/proposal-upsert/
MIT License
204 stars 14 forks source link

Description sounds just like `.set` #16

Closed UziTech closed 4 years ago

UziTech commented 4 years ago

We propose the addition of a method that will add a value to a map if the map does not already have something at key, and will also update an existing value at key.

According to MDN Map.prototype.set():

The set() method adds or updates an element with a specified key and a value to a Map object.


So both will insert a value at key if it doesn't exist and update the value at key if it does exist?

ljharb commented 4 years ago

.set does not provide a facility to differentiate how to produce the value for addition vs for updates; upsert does.

UziTech commented 4 years ago

I see, so the important part is running a given function that sets a key based on the current value (or lack there of) of the key.