Add isNullOrEmpty() to Array, Collection, and Map. Fixes KT-23279

This commit is contained in:
Mon_chi
2018-04-13 13:21:30 +03:00
committed by Ilya Gorbunov
parent 292f69936b
commit d0788148e2
4 changed files with 27 additions and 5 deletions
@@ -37,3 +37,9 @@ public fun <T, R> Array<out Pair<T, R>>.unzip(): Pair<List<T>, List<R>> {
}
return listT to listR
}
/**
* Returns `true` if this array is null or empty.
* @sample samples.collections.Arrays.Usage.arrayIsNullOrEmpty
*/
public fun Array<*>?.isNullOrEmpty(): Boolean = this == null || this.isEmpty()
@@ -140,6 +140,10 @@ private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.isNotEmpty(): Boolean = !isEmpty()
/** Returns `true` if this map is null or empty. */
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>?.isNullOrEmpty(): Boolean = this == null || isEmpty()
/**
* Returns the [Map] if its not `null`, or the empty [Map] otherwise.
*/