asSequence returns empty sequence singleton for empty arrays and strings.

#KT-8450 Fixed
This commit is contained in:
Ilya Gorbunov
2015-07-10 19:15:56 +03:00
parent 5f8a652a38
commit 96b79eebe7
2 changed files with 21 additions and 1 deletions
@@ -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