Mark
12/30/2020, 12:11 PMinline fun <reified K, V> Map<out K?, V>.filterKeyNotNull(): Map<K, V> =
mapNotNull { (key, value) -> if (key != null) key to value else null }.toMap()
Milan Hruban
12/30/2020, 12:34 PMmap.filterKeys { it != null }
Mark
12/30/2020, 1:12 PMfun <K, V> Map<out K, V>.filterKeys(predicate: (K) -> Boolean): Map<K, V>
It could be cast like this:
fun <K, V> Map<out K?, V>.filterKeyNotNull(): Map<K, V> =
filterKeys { it != null } as Map<K, V>
Ivan Pavlov
12/30/2020, 3:14 PM