Closed dead-claudia closed 3 years ago
Closing as this...isn't the best of ideas, and in essence requires an unelidable allocation every update (making it even more of a bad candidate for a replacement). Also, it's not particularly idiomatic for the JS standard library.
H/T to @bergus for the idea.
The idea is using an optional value. Also, I'd drop the map and key parameters in the callback - they're redundant and I don't see them garnering much use anyways.
Here's some examples of how it might be used:
For the no-op case, it's as simple as this:
map.update(key, (existing, none) => existing)
. Andmap.set(key, value)
is equivalent tomap.update(key, () => value)