1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-05-31 23:15:21 +00:00
tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/Map.kt
2018-12-26 16:21:52 +08:00

19 lines
448 B
Kotlin

package com.github.insanusmokrassar.TelegramBotAPI.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()