any easy way to increment a value of a key in map?...
# getting-started
p
any easy way to increment a value of a key in map? even if the mapping does not exist yet?
s
I used something like this recently, not sure if there’s a more concise method
Copy code
map[key] = map.getOrPut(key) { 0 }.inc()
👍 1
p
i ended up calling
.withDefault()
when creating the map and then just
map[key] = map[key] + 1
👍 1
k
Does that work? You need
.getValue()
then, right?
2
344 Views