Add sample for emptySet
This commit is contained in:
committed by
Ilya Gorbunov
parent
11696ac4c0
commit
31d650a041
@@ -257,6 +257,22 @@ class Collections {
|
||||
}
|
||||
}
|
||||
|
||||
class Sets {
|
||||
|
||||
@Sample
|
||||
fun emptyReadOnlySet() {
|
||||
val set = setOf<String>()
|
||||
assertTrue(set.isEmpty())
|
||||
|
||||
// another way to create an empty set,
|
||||
// type parameter is inferred from the expected type
|
||||
val other: Set<Int> = emptySet()
|
||||
|
||||
assertTrue(set == other, "Empty sets are equal")
|
||||
assertPrints(set, "[]")
|
||||
}
|
||||
}
|
||||
|
||||
class Transformations {
|
||||
|
||||
@Sample
|
||||
|
||||
@@ -22,7 +22,10 @@ internal object EmptySet : Set<Nothing>, Serializable {
|
||||
}
|
||||
|
||||
|
||||
/** Returns an empty read-only set. The returned set is serializable (JVM). */
|
||||
/**
|
||||
* Returns an empty read-only set. The returned set is serializable (JVM).
|
||||
* @sample samples.collections.Collections.Sets.emptyReadOnlySet
|
||||
*/
|
||||
public fun <T> emptySet(): Set<T> = EmptySet
|
||||
/**
|
||||
* Returns a new read-only set with the given elements.
|
||||
@@ -31,7 +34,10 @@ public fun <T> emptySet(): Set<T> = EmptySet
|
||||
*/
|
||||
public fun <T> setOf(vararg elements: T): Set<T> = if (elements.size > 0) elements.toSet() else emptySet()
|
||||
|
||||
/** Returns an empty read-only set. The returned set is serializable (JVM). */
|
||||
/**
|
||||
* Returns an empty read-only set. The returned set is serializable (JVM).
|
||||
* @sample samples.collections.Collections.Sets.emptyReadOnlySet
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> setOf(): Set<T> = emptySet()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user