tc39 / proposal-collection-methods

https://tc39.github.io/proposal-collection-methods/
Other
172 stars 8 forks source link

Map.update() with 2 args shouldn't throw if key doesn't exist in map #35

Open tabatkins opened 5 years ago

tabatkins commented 5 years ago

The current proposal for Map.update() tests to see if the key exists in the map; if it doesn't, and you didn't pass a default-value thunk, it throws.

I think this should instead just pass undefined to the update function. This matches the current philosophy behind Map.get(), which purposely does not throw when the key doesn't exist. If we ever extend Map.get() to have a default-value thunk as well, then calling m.get("doesn't exist") wont' suddenly start throwing; it'll just continue returning undefined as today, and .update() should do the same.

I don't want to have to write a no-op _=>{} just to avoid errors when I don't care about them. ^_^