asSequence returns empty sequence singleton for empty arrays and strings.
#KT-8450 Fixed
This commit is contained in:
@@ -26,7 +26,6 @@ fun sequences(): List<GenericFunction> {
|
||||
}
|
||||
templates add f("asSequence()") {
|
||||
include(Maps)
|
||||
exclude(Sequences)
|
||||
doc { "Returns a sequence from the given collection." }
|
||||
returns("Sequence<T>")
|
||||
body {
|
||||
@@ -39,6 +38,17 @@ fun sequences(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(ArraysOfObjects, ArraysOfPrimitives, Strings) {
|
||||
"""
|
||||
if (isEmpty()) return emptySequence()
|
||||
return object : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> {
|
||||
return this@asSequence.iterator()
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
body(Sequences) {
|
||||
"""
|
||||
return this
|
||||
|
||||
Reference in New Issue
Block a user