Add sample for orEmpty method
This commit is contained in:
@@ -119,6 +119,15 @@ class Maps {
|
|||||||
assertFalse(map.isNullOrEmpty())
|
assertFalse(map.isNullOrEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sample
|
||||||
|
fun mapOrEmpty() {
|
||||||
|
val nullMap: Map<String, Any>? = null
|
||||||
|
assertPrints(nullMap.orEmpty(), "{}")
|
||||||
|
|
||||||
|
val map: Map<Char, Int>? = mapOf('a' to 1, 'b' to 2, 'c' to 3)
|
||||||
|
assertPrints(map.orEmpty(), "{a=1, b=2, c=3}")
|
||||||
|
}
|
||||||
|
|
||||||
@Sample
|
@Sample
|
||||||
fun mapIfEmpty() {
|
fun mapIfEmpty() {
|
||||||
val emptyMap: Map<String, Int> = emptyMap()
|
val emptyMap: Map<String, Int> = emptyMap()
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ public inline fun <K, V> Map<out K, V>?.isNullOrEmpty(): Boolean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the [Map] if its not `null`, or the empty [Map] otherwise.
|
* Returns the [Map] if its not `null`, or the empty [Map] otherwise.
|
||||||
|
*
|
||||||
|
* @sample samples.collections.Maps.Usage.mapOrEmpty
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun <K, V> Map<K, V>?.orEmpty(): Map<K, V> = this ?: emptyMap()
|
public inline fun <K, V> Map<K, V>?.orEmpty(): Map<K, V> = this ?: emptyMap()
|
||||||
|
|||||||
Reference in New Issue
Block a user