Make stream plus operation actually streaming (lazy).
This commit is contained in:
committed by
Andrey Breslav
parent
c5b0351aa7
commit
108fdc0097
@@ -16,6 +16,7 @@ fun generateCollectionsAPI(outDir : File) {
|
||||
guards().writeTo(File(outDir, "_Guards.kt")) { build() }
|
||||
generators().writeTo(File(outDir, "_Generators.kt")) { build() }
|
||||
strings().writeTo(File(outDir, "_Strings.kt")) { build() }
|
||||
streams().writeTo(File(outDir, "_Streams.kt")) { build() }
|
||||
specialJVM().writeTo(File(outDir, "_SpecialJVM.kt")) { build() }
|
||||
|
||||
numeric().writeTo(File(outDir, "_Numeric.kt")) {
|
||||
|
||||
@@ -18,12 +18,9 @@ fun generators(): List<GenericFunction> {
|
||||
|
||||
doc(Streams) { "Returns a stream containing all elements of original stream and then the given element" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
// TODO: Implement lazy behavior
|
||||
body(Streams) {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer.stream()
|
||||
return Multistream(streamOf(this, streamOf(element)))
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -32,7 +29,6 @@ fun generators(): List<GenericFunction> {
|
||||
exclude(Streams)
|
||||
doc { "Returns a list containing all elements of original collection and then all elements of the given *collection*" }
|
||||
returns("List<T>")
|
||||
|
||||
body {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
@@ -46,7 +42,6 @@ fun generators(): List<GenericFunction> {
|
||||
exclude(Streams)
|
||||
doc { "Returns a list containing all elements of original collection and then all elements of the given *collection*" }
|
||||
returns("List<T>")
|
||||
|
||||
body {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
@@ -60,13 +55,9 @@ fun generators(): List<GenericFunction> {
|
||||
only(Streams)
|
||||
doc { "Returns a stream containing all elements of original stream and then all elements of the given *collection*" }
|
||||
returns("Stream<T>")
|
||||
|
||||
// TODO: Implement lazy behavior
|
||||
body {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer.stream()
|
||||
return Multistream(streamOf(this, collection.stream()))
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -76,11 +67,8 @@ fun generators(): List<GenericFunction> {
|
||||
doc { "Returns a stream containing all elements of original stream and then all elements of the given *stream*" }
|
||||
returns("Stream<T>")
|
||||
body {
|
||||
// TODO: Implement lazy behavior
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
answer.addAll(stream)
|
||||
return answer.stream()
|
||||
return Multistream(streamOf(this, stream))
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package templates
|
||||
|
||||
import templates.Family.*
|
||||
|
||||
fun streams(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("stream()") {
|
||||
doc { "Returns a stream from the given collection" }
|
||||
returns("Stream<T>")
|
||||
body {
|
||||
"""
|
||||
return object : Stream<T> { override fun iterator() : Iterator<T> { return this@stream.iterator() } }
|
||||
"""
|
||||
}
|
||||
|
||||
body(Streams) {
|
||||
"""
|
||||
return this
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
Reference in New Issue
Block a user