Add sample for emptySet

This commit is contained in:
Andre Perkins
2018-01-06 19:04:55 -05:00
committed by Ilya Gorbunov
parent 11696ac4c0
commit 31d650a041
2 changed files with 24 additions and 2 deletions
@@ -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()