Skip to content

Instantly share code, notes, and snippets.

@viartemev
Created December 16, 2020 14:33
Show Gist options
  • Save viartemev/b347e6e25ca723fba1635d2bddd63c50 to your computer and use it in GitHub Desktop.
Save viartemev/b347e6e25ca723fba1635d2bddd63c50 to your computer and use it in GitHub Desktop.
fun <K, V: Any> Map<K, V?>.filterValuesNotNull(): Map<K, V> {
val map = HashMap(this)
val result = LinkedHashMap<K, V>()
for (entry in map) {
if (entry.value != null) {
result[entry.key] = entry.value
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment