1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-02 07:55:25 +00:00
tgbotapi/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/Map.kt

19 lines
423 B
Kotlin

package dev.inmo.tgbotapi.utils
fun <K, V> mapOfNotNull(vararg pairs: Pair<K, V?>): Map<K, V> {
return HashMap<K, V>().apply {
pairs.forEach {
(key, value) ->
value ?.also {
put(key, it)
}
}
}
}
fun <K, V> Map<K, V?>.mapNotNullValues(): Map<K, V> = asSequence().mapNotNull {
it.value ?.let { value ->
it.key to value
}
}.toMap()