Ruckus
03/03/2019, 9:57 PMpublic inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
val value = get(key)
return if (value == null) {
val answer = defaultValue()
put(key, answer)
answer
} else {
value
}
}
but it seems to me (based on the kdoc) that is should be more like
public inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
return if (contains(key)) {
getValue(key)
} else {
val answer = defaultValue()
put(key, answer)
answer
}
}
Dico
03/03/2019, 10:16 PMV
were constrained to Any
(<K, V : Any>
).
So yeah, I would say that you're correctRuckus
03/03/2019, 10:31 PMilya.gorbunov
03/03/2019, 10:44 PMcompute
etc, that do not distinguish null
and missing value.Ruckus
03/03/2019, 10:46 PM