fun <K, V> Map<K, V?>.filterValuesNotNull() = filterValues { it != null } as Map<K, V>
? I'm not sure I would even define it at all
p
pdegand
07/19/2018, 4:19 PM
the cast is unchecked
pdegand
07/19/2018, 4:21 PM
i defined mine like that :
Copy code
fun <K, V> Map<out K, V?>.filterValuesNotNull(): Map<K, V> {
val result = LinkedHasMap<K, V>()
for (entry in this) {
entry.value?.let { result[entry.key] = it }
}
}
mostly copied from
filterValues
of stdlib
a
arekolek
07/19/2018, 5:08 PM
even though it's unchecked, I don't see how it could fail