Rohde Fischer
09/21/2024, 10:46 AMval 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)