commonMain.com.lt.lazy_people_http.Util.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of LazyPeopleHttp-lib-jvm Show documentation
Show all versions of LazyPeopleHttp-lib-jvm Show documentation
Lazy people http, Retrofit of kmp all targets
package com.lt.lazy_people_http
/**
* creator: lt 2022/10/21 [email protected]
* effect : 工具类
* warning:
*/
/**
* 如果字符串为空或长度为0,就使用lambda中的字符串
*/
internal inline fun String?.ifNullOfEmpty(defaultValue: () -> String): String =
if (this.isNullOrEmpty()) defaultValue() else this
/**
* 将两个map合并为一个map
*/
internal fun mergeMap(
map1: Map?,
map2: Map?
): Map? {
return if (map1 == null)
map2
else if (map2 == null)
map1
else
map1 + map2
}
/**
* 将map变平为array
*/
fun Map._lazyPeopleHttpFlatten(): Array {
val kvs = entries.toList()
return Array(size * 2) {
val entry = kvs[it / 2]
if (it % 2 == 0)
entry.key
else
entry.value
}
}