Add sample for Map.asSequence (#5055)
This commit is contained in:
@@ -584,6 +584,8 @@ public inline fun <K, V> Map<out K, V>.asIterable(): Iterable<Map.Entry<K, V>> {
|
||||
|
||||
/**
|
||||
* Creates a [Sequence] instance that wraps the original map returning its entries when being iterated.
|
||||
*
|
||||
* @sample samples.collections.Sequences.Building.sequenceFromMap
|
||||
*/
|
||||
public fun <K, V> Map<out K, V>.asSequence(): Sequence<Map.Entry<K, V>> {
|
||||
return entries.asSequence()
|
||||
|
||||
@@ -75,6 +75,14 @@ class Sequences {
|
||||
assertPrints(sequence.joinToString(), "a, b, c")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun sequenceFromMap() {
|
||||
val map = mapOf(1 to "x", 2 to "y", -1 to "zz")
|
||||
val sequence = map.asSequence()
|
||||
|
||||
assertPrints(sequence.joinToString(), "1=x, 2=y, -1=zz")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun sequenceFromIterator() {
|
||||
val array = arrayOf(1, 2, 3)
|
||||
|
||||
@@ -43,7 +43,7 @@ object SequenceOps : TemplateGroupBase() {
|
||||
Creates a [Sequence] instance that wraps the original ${f.collection} returning its ${f.element.pluralize()} when being iterated.
|
||||
"""
|
||||
}
|
||||
specialFor(ArraysOfPrimitives, ArraysOfObjects, Iterables) {
|
||||
specialFor(ArraysOfPrimitives, ArraysOfObjects, Iterables, Maps) {
|
||||
sample("samples.collections.Sequences.Building.sequenceFrom${f.doc.collection.capitalize()}")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user