Hi everyone. Could you recommend the best way to i...
# random
i
Hi everyone. Could you recommend the best way to implement function, that accepts map with nullable key type and returns the same one without null keys and non-nullable key type? I found to ways, but I don't like both of them...
Copy code
fun mapWithoutNullKeys(myMap: Map<String?, String>): Map<String, String> = myMap
    .map { it.key to it.value }
    .filterIsInstance<Pair<String, String>>()
    .toMap()
because a lot of transformations and some overhead or
Copy code
fun mapWithoutNullKeys(myMap: Map<String?, String>): Map<String, String> {
    return myMap.filterKeys { it != null } as Map<String, String>
}
because of unchecked cast. Maybe there is some method from stdlib for that task?