I’m surprised there is not something for this in t...
# codereview
m
I’m surprised there is not something for this in the standard lib. Is this okay or maybe remove inline/reified?
Copy code
inline fun <reified K, V> Map<out K?, V>.filterKeyNotNull(): Map<K, V> =
    mapNotNull { (key, value) -> if (key != null) key to value else null }.toMap()
m
why not use
map.filterKeys { it != null }
m
It returns type `Map<K?, V>`:
Copy code
fun <K, V> Map<out K, V>.filterKeys(predicate: (K) -> Boolean): Map<K, V>
It could be cast like this:
Copy code
fun <K, V> Map<out K?, V>.filterKeyNotNull(): Map<K, V> =
    filterKeys { it != null } as Map<K, V>
i
I have 3 years experience and I've never used maps with nullable keys. If it is not in standard library probably it is really rare use case and it's just not worth to add such function