frogger
12/04/2020, 2:20 PMMap<K,V?>
to Map<K,V>
? I.e. filter all null values and cast the map?Ryan
12/04/2020, 2:25 PMRyan
12/04/2020, 2:26 PMfrogger
12/04/2020, 2:29 PMVampire
12/04/2020, 2:39 PMVampire
12/04/2020, 2:40 PMnull
values you can do .filterValues { it != null }
Vampire
12/04/2020, 2:43 PM.filterValues { it != null }.mapValues { it.value as V }
Vampire
12/04/2020, 2:45 PMfun <K, V> Map<K, V?>.filterValuesNotNull() =
filterValues { it != null }.mapValues { it.value as V }
Tobias Berger
12/04/2020, 2:57 PMmyKey in myMap
can return true, but myMap[myKey]
would still return null
• when using entries
, forEach
or something alike, you can get entries with null
values
• Basically everything except for the simple get
call behaves differentlyfrogger
12/04/2020, 3:04 PMmapValues
variant looks mjuch nicer than the cast I did, will try that, thanks!