tc39 / proposal-upsert

ECMAScript Proposal, specs, and reference implementation for Map.prototype.upsert

Home Page:https://tc39.es/proposal-upsert/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description sounds just like `.set`

UziTech opened this issue · comments

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?

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

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.