Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/ktextension/ArrayExtensions.kt

27 lines
610 B
Kotlin
Raw Normal View History

2017-01-12 17:26:44 +01:00
package org.mariotaku.ktextension
/**
* Created by mariotaku on 2017/1/12.
*/
fun Array<*>?.isNotNullOrEmpty(): Boolean {
return this != null && this.isNotEmpty()
}
fun Array<*>?.isNullOrEmpty(): Boolean {
return this == null || this.isEmpty()
}
2017-02-10 16:38:59 +01:00
fun <T : Any> Array<T>.toNulls(): Array<T?> {
@Suppress("UNCHECKED_CAST")
return this as Array<T?>
2017-02-10 19:01:31 +01:00
}
fun <T : Any> Array<T>.toStringArray(): Array<String> {
return Array(size) { this[it].toString() }
}
2017-04-14 09:05:51 +02:00
inline fun <T : Any, reified R : Any> Array<T>.mapToArray(transform: (T) -> R): Array<R> {
return map(transform).toTypedArray()
}