I want to do something along the lines of: ```val...
# stdlib
r
I want to do something along the lines of:
Copy code
val map: Map<Key, Value> = emptymap().withDefault { defaultValue }

val basedOnMap = map + (newKey to newValue)

val shouldBeDefault = basedOnMap.getValue(differentKey)
but it seems that the
basedOnMap
does not retain the default value, so when I do
getValue(differentKey)
I get an exception rather than the expected
defaultValue
. IIs there a way to deal with this? E.g. a
plusValue
or some way of doing
(map + pair).withDefault { map.defaultValue }
or similar (assume a context where I don't necessarily have obvious access to the default value)