diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index d7582dbdd38..16655662d3e 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -10506,7 +10506,7 @@ public fun ShortArray.asIterable(): Iterable { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun Array.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10518,7 +10518,7 @@ public fun Array.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun BooleanArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10530,7 +10530,7 @@ public fun BooleanArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun ByteArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10542,7 +10542,7 @@ public fun ByteArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun CharArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10554,7 +10554,7 @@ public fun CharArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun DoubleArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10566,7 +10566,7 @@ public fun DoubleArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun FloatArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10578,7 +10578,7 @@ public fun FloatArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun IntArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10590,7 +10590,7 @@ public fun IntArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun LongArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() @@ -10602,7 +10602,7 @@ public fun LongArray.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original array returning its elements when being iterated. */ public fun ShortArray.asSequence(): Sequence { if (isEmpty()) return emptySequence() diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 1d1ed3151b5..f289f515c07 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -1769,7 +1769,7 @@ public fun Iterable.asIterable(): Iterable { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original collection returning its elements when being iterated. */ public fun Iterable.asSequence(): Sequence { return object : Sequence { diff --git a/libraries/stdlib/src/generated/_Maps.kt b/libraries/stdlib/src/generated/_Maps.kt index 545f1c65576..3a4fb8c8526 100644 --- a/libraries/stdlib/src/generated/_Maps.kt +++ b/libraries/stdlib/src/generated/_Maps.kt @@ -196,7 +196,7 @@ public fun Map.asIterable(): Iterable> { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original map returning its entrys when being iterated. */ public fun Map.asSequence(): Sequence> { return object : Sequence> { diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index d6f0568f978..97f62ca5bee 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -1085,7 +1085,7 @@ public fun Sequence.asIterable(): Iterable { } /** - * Returns a sequence from the given collection. + * Returns this sequence as a [Sequence]. */ public fun Sequence.asSequence(): Sequence { return this diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index cd64474447c..a157fd71566 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -1618,7 +1618,7 @@ public fun CharSequence.asIterable(): Iterable { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original char sequence returning its characters when being iterated. */ public fun CharSequence.asSequence(): Sequence { if (this is String && isEmpty()) return emptySequence() @@ -1630,7 +1630,7 @@ public fun CharSequence.asSequence(): Sequence { } /** - * Returns a sequence from the given collection. + * Creates a [Sequence] instance that wraps the original string returning its characters when being iterated. */ @Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) public fun String.asSequence(): Sequence { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt index 2d8368d96f5..ebb9eaaa29f 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt @@ -28,10 +28,15 @@ fun sequences(): List { templates add f("asSequence()") { include(Maps) - doc { "Returns a sequence from the given collection." } + doc { f -> "Creates a [Sequence] instance that wraps the original ${f.collection} returning its ${f.element}s when being iterated." } returns("Sequence") - body { + body { f -> """ + ${ when(f) { + ArraysOfObjects, ArraysOfPrimitives -> "if (isEmpty()) return emptySequence()" + CharSequences -> "if (this is String && isEmpty()) return emptySequence()" + else -> "" + }} return object : Sequence { override fun iterator(): Iterator { return this@asSequence.iterator() @@ -40,16 +45,7 @@ fun sequences(): List { """ } - body(ArraysOfObjects, ArraysOfPrimitives) { - """ - if (isEmpty()) return emptySequence() - return object : Sequence { - override fun iterator(): Iterator { - return this@asSequence.iterator() - } - } - """ - } + // TODO: Drop special case deprecate(Strings) { forBinaryCompatibility } body(CharSequences, Strings) { @@ -63,11 +59,8 @@ fun sequences(): List { """ } - body(Sequences) { - """ - return this - """ - } + doc(Sequences) { "Returns this sequence as a [Sequence]."} + body(Sequences) { "return this" } } return templates