1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-16 13:23:47 +00:00
tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/Map.kt

19 lines
448 B
Kotlin
Raw Normal View History

2018-12-26 08:07:24 +00:00
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()