Closed tabatkins closed 5 years ago
That sounds like great addition. I'm not sure if (new Map).update("Foo", v => 1)
should throw or create new entry.
How about update(key, fn, defaultValue)
? This would be especially useful for grouping and counting.
If we're going to have defaultValue
, it should be a thunk, not a value, so that it can be lazily evaluated only if needed.
That sounds like great addition. I'm not sure if
(new Map).update("Foo", v => 1)
should throw or create new entry.How about
update(key, fn, defaultValue)
? This would be especially useful for grouping and counting.
I think it should create a new value, with the old value being undefined
. And yeah, add a defaultValue
thunk as well. ^_^
Right now, if you want to update the value of a key in a map, you have to do a set/get dance and repeat yourself:
It might be worthwhile to combine these into one operation:
This is a little shorter, which is nice, but more importantly you don't repeat
myMap
andkey
, which is important if either of them are expressions rather than literals or variables. Because of the current repetition, the length savings also compound if either of those are long names. For example, the current way to increment an element's width in CSS Typed OM is:which would shorten to
That feels like a significant usability improvement.