Rename Stream<T> to Sequence<T> and provide migration path via deprecated types and functions.
This commit is contained in:
@@ -17,7 +17,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() }
|
||||
sequences().writeTo(File(outDir, "_Sequences.kt")) { build() }
|
||||
specialJVM().writeTo(File(outDir, "_SpecialJVM.kt")) { build() }
|
||||
ranges().writeTo(File(outDir, "_Ranges.kt")) { build() }
|
||||
|
||||
@@ -26,7 +26,7 @@ fun generateCollectionsAPI(outDir: File) {
|
||||
// TODO: decide if sum for byte and short is needed and how to make it work
|
||||
for (numeric in listOf(PrimitiveType.Int, PrimitiveType.Long, /*Byte, Short, */ PrimitiveType.Double, PrimitiveType.Float)) {
|
||||
build(builder, Iterables, numeric)
|
||||
build(builder, Streams, numeric)
|
||||
build(builder, Sequences, numeric)
|
||||
}
|
||||
|
||||
for (numeric in listOf(PrimitiveType.Int, PrimitiveType.Long, PrimitiveType.Byte, PrimitiveType.Short, PrimitiveType.Double, PrimitiveType.Float)) {
|
||||
|
||||
@@ -192,7 +192,7 @@ fun elements(): List<GenericFunction> {
|
||||
throw IndexOutOfBoundsException("Collection doesn't contain element at index")
|
||||
"""
|
||||
}
|
||||
body(Streams) {
|
||||
body(Sequences) {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
var count = 0
|
||||
@@ -331,7 +331,7 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Streams) {
|
||||
body(Sequences) {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -371,7 +371,7 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Streams) {
|
||||
body(Sequences) {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package templates
|
||||
|
||||
import java.util.ArrayList
|
||||
import templates.Family.*
|
||||
import java.util.HashSet
|
||||
import java.util.HashMap
|
||||
import java.io.StringReader
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.StringTokenizer
|
||||
|
||||
enum class Family {
|
||||
Streams
|
||||
Sequences
|
||||
Iterables
|
||||
Collections
|
||||
Lists
|
||||
@@ -21,19 +21,19 @@ enum class Family {
|
||||
}
|
||||
|
||||
enum class PrimitiveType(val name: String) {
|
||||
Boolean: PrimitiveType("Boolean")
|
||||
Byte: PrimitiveType("Byte")
|
||||
Char: PrimitiveType("Char")
|
||||
Short: PrimitiveType("Short")
|
||||
Int: PrimitiveType("Int")
|
||||
Long: PrimitiveType("Long")
|
||||
Float: PrimitiveType("Float")
|
||||
Double: PrimitiveType("Double")
|
||||
Boolean : PrimitiveType("Boolean")
|
||||
Byte : PrimitiveType("Byte")
|
||||
Char : PrimitiveType("Char")
|
||||
Short : PrimitiveType("Short")
|
||||
Int : PrimitiveType("Int")
|
||||
Long : PrimitiveType("Long")
|
||||
Float : PrimitiveType("Float")
|
||||
Double : PrimitiveType("Double")
|
||||
}
|
||||
|
||||
|
||||
class GenericFunction(val signature: String, val keyword: String = "fun") : Comparable<GenericFunction> {
|
||||
val defaultFamilies = array(Iterables, Streams, ArraysOfObjects, ArraysOfPrimitives, Strings)
|
||||
val defaultFamilies = array(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, Strings)
|
||||
|
||||
var toNullableT: Boolean = false
|
||||
|
||||
@@ -45,7 +45,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
private val buildPrimitives = HashSet(PrimitiveType.values().toList())
|
||||
|
||||
var deprecate: String = ""
|
||||
val deprecates = HashMap<Family, String>()
|
||||
val deprecates = hashMapOf<Family, String>()
|
||||
|
||||
var doc: String = ""
|
||||
val docs = HashMap<Family, String>()
|
||||
@@ -159,7 +159,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
}
|
||||
|
||||
fun build(builder: StringBuilder, f: Family) {
|
||||
if (f == ArraysOfPrimitives || f == RangesOfPrimitives || f == ProgressionsOfPrimitives) {
|
||||
if (f == ArraysOfPrimitives || f == RangesOfPrimitives || f == ProgressionsOfPrimitives) {
|
||||
for (primitive in buildPrimitives.sortBy { it.name() })
|
||||
build(builder, f, primitive)
|
||||
} else {
|
||||
@@ -168,6 +168,23 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
}
|
||||
|
||||
fun build(builder: StringBuilder, f: Family, primitive: PrimitiveType?) {
|
||||
if (f == Sequences) {
|
||||
val text = StringBuilder {
|
||||
doBuild(this, f, primitive)
|
||||
}.toString()
|
||||
builder.append(text)
|
||||
builder.appendln()
|
||||
builder.appendln("deprecated(\"Migrate to using Sequence<T> and respective functions\")")
|
||||
val streamText = text
|
||||
.replace("Sequence", "Stream")
|
||||
.replace("sequence", "stream")
|
||||
.replace("MultiStream", "Multistream")
|
||||
builder.append(streamText)
|
||||
} else
|
||||
doBuild(builder, f, primitive)
|
||||
}
|
||||
|
||||
fun doBuild(builder: StringBuilder, f: Family, primitive: PrimitiveType?) {
|
||||
val returnType = returnTypes[f] ?: defaultReturnType
|
||||
if (returnType.isEmpty())
|
||||
throw RuntimeException("No return type specified for $signature")
|
||||
@@ -178,7 +195,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
Collections -> "Collection<$isAsteriskOrT>"
|
||||
Lists -> "List<$isAsteriskOrT>"
|
||||
Maps -> "Map<K, V>"
|
||||
Streams -> "Stream<$isAsteriskOrT>"
|
||||
Sequences -> "Sequence<$isAsteriskOrT>"
|
||||
ArraysOfObjects -> "Array<$isAsteriskOrT>"
|
||||
Strings -> "String"
|
||||
ArraysOfPrimitives -> primitive?.let { it.name() + "Array" } ?: throw IllegalArgumentException("Primitive array should specify primitive type")
|
||||
@@ -301,7 +318,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
builder.append('\n')
|
||||
StringReader(body).forEachLine {
|
||||
var count = indent
|
||||
val line = it.dropWhile { count-- > 0 && it == ' ' } .renderType()
|
||||
val line = it.dropWhile { count-- > 0 && it == ' ' }.renderType()
|
||||
if (line.isNotEmpty()) {
|
||||
builder.append(" ").append(line)
|
||||
builder.append("\n")
|
||||
|
||||
@@ -19,11 +19,11 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
doc(Streams) { "Returns a stream containing all elements except first [n] elements" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
doc(Sequences) { "Returns a sequence containing all elements except first [n] elements" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return DropStream(this, n)
|
||||
return DropSequence(this, n)
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ fun filtering(): List<GenericFunction> {
|
||||
body(Strings) { "return substring(0, Math.min(n, length()))" }
|
||||
returns(Strings) { "String" }
|
||||
|
||||
doc(Streams) { "Returns a stream containing first *n* elements" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
doc(Sequences) { "Returns a sequence containing first *n* elements" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return TakeStream(this, n)
|
||||
return TakeSequence(this, n)
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -122,12 +122,12 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
inline(false, Streams)
|
||||
doc(Streams) { "Returns a stream containing all elements except first elements that satisfy the given [predicate]" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
inline(false, Sequences)
|
||||
doc(Sequences) { "Returns a sequence containing all elements except first elements that satisfy the given [predicate]" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return DropWhileStream(this, predicate)
|
||||
return DropWhileSequence(this, predicate)
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -162,12 +162,12 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
inline(false, Streams)
|
||||
doc(Streams) { "Returns a stream containing first elements satisfying the given [predicate]" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
inline(false, Sequences)
|
||||
doc(Sequences) { "Returns a sequence containing first elements satisfying the given [predicate]" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return TakeWhileStream(this, predicate)
|
||||
return TakeWhileSequence(this, predicate)
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -191,12 +191,12 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
inline(false, Streams)
|
||||
doc(Streams) { "Returns a stream containing all elements matching the given [predicate]" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
inline(false, Sequences)
|
||||
doc(Sequences) { "Returns a sequence containing all elements matching the given [predicate]" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return FilteringStream(this, true, predicate)
|
||||
return FilteringSequence(this, true, predicate)
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -246,12 +246,12 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
inline(false, Streams)
|
||||
doc(Streams) { "Returns a stream containing all elements not matching the given [predicate]" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
inline(false, Sequences)
|
||||
doc(Sequences) { "Returns a sequence containing all elements not matching the given [predicate]" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return FilteringStream(this, false, predicate)
|
||||
return FilteringSequence(this, false, predicate)
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -291,11 +291,11 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
doc(Streams) { "Returns a stream containing all elements that are not null" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
doc(Sequences) { "Returns a sequence containing all elements that are not null" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return FilteringStream(this, false, { it == null }) as Stream<T>
|
||||
return FilteringSequence(this, false, { it == null }) as Sequence<T>
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,17 @@ fun generators(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
doc(Streams) { "Returns a stream containing all elements of original stream and then the given element" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
body(Streams) {
|
||||
doc(Sequences) { "Returns a sequence containing all elements of original sequence and then the given element" }
|
||||
returns(Sequences) { "Sequence<T>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return Multistream(streamOf(this, streamOf(element)))
|
||||
return MultiSequence(sequenceOf(this, sequenceOf(element)))
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("plus(collection: Iterable<T>)") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a list containing all elements of original collection and then all elements of the given *collection*" }
|
||||
returns("List<T>")
|
||||
body {
|
||||
@@ -40,7 +40,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("plus(array: Array<out T>)") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a list containing all elements of original collection and then all elements of the given *collection*" }
|
||||
returns("List<T>")
|
||||
body {
|
||||
@@ -53,23 +53,23 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("plus(collection: Iterable<T>)") {
|
||||
only(Streams)
|
||||
doc { "Returns a stream containing all elements of original stream and then all elements of the given *collection*" }
|
||||
returns("Stream<T>")
|
||||
only(Sequences)
|
||||
doc { "Returns a sequence containing all elements of original sequence and then all elements of the given [collection]" }
|
||||
returns("Sequence<T>")
|
||||
body {
|
||||
"""
|
||||
return Multistream(streamOf(this, collection.stream()))
|
||||
return MultiSequence(sequenceOf(this, collection.sequence()))
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("plus(stream: Stream<T>)") {
|
||||
only(Streams)
|
||||
doc { "Returns a stream containing all elements of original stream and then all elements of the given *stream*" }
|
||||
returns("Stream<T>")
|
||||
templates add f("plus(sequence: Sequence<T>)") {
|
||||
only(Sequences)
|
||||
doc { "Returns a sequence containing all elements of original sequence and then all elements of the given [sequence]" }
|
||||
returns("Sequence<T>")
|
||||
body {
|
||||
"""
|
||||
return Multistream(streamOf(this, stream))
|
||||
return MultiSequence(sequenceOf(this, sequence))
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ fun generators(): List<GenericFunction> {
|
||||
while *second* collection contains elements for which predicate yielded *false*
|
||||
"""
|
||||
}
|
||||
// TODO: Stream variant
|
||||
// TODO: Sequence variant
|
||||
returns("Pair<List<T>, List<T>>")
|
||||
body {
|
||||
"""
|
||||
@@ -119,7 +119,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("merge(other: Iterable<R>, transform: (T, R) -> V)") {
|
||||
exclude(Streams, Strings)
|
||||
exclude(Sequences, Strings)
|
||||
doc {
|
||||
"""
|
||||
Returns a list of values built from elements of both collections with same indexes using provided *transform*. List has length of shortest collection.
|
||||
@@ -154,7 +154,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("merge(array: Array<out R>, transform: (T, R) -> V)") {
|
||||
exclude(Streams, Strings)
|
||||
exclude(Sequences, Strings)
|
||||
doc {
|
||||
"""
|
||||
Returns a list of values built from elements of both collections with same indexes using provided *transform*. List has length of shortest collection.
|
||||
@@ -190,26 +190,26 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
|
||||
templates add f("merge(stream: Stream<R>, transform: (T, R) -> V)") {
|
||||
only(Streams)
|
||||
templates add f("merge(sequence: Sequence<R>, transform: (T, R) -> V)") {
|
||||
only(Sequences)
|
||||
doc {
|
||||
"""
|
||||
Returns a stream of values built from elements of both collections with same indexes using provided *transform*. Stream has length of shortest stream.
|
||||
Returns a sequence of values built from elements of both collections with same indexes using provided *transform*. Resulting sequence has length of shortest input sequences.
|
||||
"""
|
||||
}
|
||||
typeParam("R")
|
||||
typeParam("V")
|
||||
returns("Stream<V>")
|
||||
returns("Sequence<V>")
|
||||
body {
|
||||
"""
|
||||
return MergingStream(this, stream, transform)
|
||||
return MergingSequence(this, sequence, transform)
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
templates add f("zip(other: Iterable<R>)") {
|
||||
exclude(Streams, Strings)
|
||||
exclude(Sequences, Strings)
|
||||
doc {
|
||||
"""
|
||||
Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
@@ -246,7 +246,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("zip(array: Array<out R>)") {
|
||||
exclude(Streams, Strings)
|
||||
exclude(Sequences, Strings)
|
||||
doc {
|
||||
"""
|
||||
Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
@@ -261,18 +261,19 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("zip(stream: Stream<R>)") {
|
||||
only(Streams)
|
||||
templates add f("zip(sequence: Sequence<R>)") {
|
||||
only(Sequences)
|
||||
doc {
|
||||
"""
|
||||
Returns a stream of pairs built from elements of both collections with same indexes. Stream has length of shortest stream.
|
||||
Returns a sequence of pairs built from elements of both collections with same indexes.
|
||||
Resulting sequence has length of shortest input sequences.
|
||||
"""
|
||||
}
|
||||
typeParam("R")
|
||||
returns("Stream<Pair<T, R>>")
|
||||
returns("Sequence<Pair<T, R>>")
|
||||
body {
|
||||
"""
|
||||
return MergingStream(this, stream) { (t1, t2) -> t1 to t2 }
|
||||
return MergingSequence(this, sequence) { (t1, t2) -> t1 to t2 }
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ fun guards(): List<GenericFunction> {
|
||||
return this as SELF
|
||||
"""
|
||||
}
|
||||
body(Streams) {
|
||||
body(Sequences) {
|
||||
"""
|
||||
return FilteringStream(this) {
|
||||
return FilteringSequence(this) {
|
||||
if (it == null) {
|
||||
throw IllegalArgumentException("null element found in $THIS")
|
||||
}
|
||||
true
|
||||
} as Stream<T>
|
||||
} as Sequence<T>
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ fun mapping(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Streams) { "Stream<Pair<Int, T>>" }
|
||||
doc(Streams) { "Returns a stream containing pairs of each element of the original collection and their index" }
|
||||
body(Streams) {
|
||||
returns(Sequences) { "Sequence<Pair<Int, T>>" }
|
||||
doc(Sequences) { "Returns a sequence containing pairs of each element of the original collection and their index" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
var index = 0
|
||||
return TransformingStream(this, { index++ to it })
|
||||
return TransformingSequence(this, { index++ to it })
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -35,11 +35,11 @@ fun mapping(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Streams) { "Stream<IndexedValue<T>>" }
|
||||
doc(Streams) { "Returns a stream of [IndexedValue] for each element of the original stream" }
|
||||
body(Streams) {
|
||||
returns(Sequences) { "Sequence<IndexedValue<T>>" }
|
||||
doc(Sequences) { "Returns a sequence of [IndexedValue] for each element of the original sequence" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return IndexingStream(this)
|
||||
return IndexingSequence(this)
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -59,11 +59,11 @@ fun mapping(): List<GenericFunction> {
|
||||
body(Strings) {
|
||||
"return mapIndexedTo(ArrayList<R>(length()), transform)"
|
||||
}
|
||||
inline(false, Streams)
|
||||
returns(Streams) { "Stream<R>" }
|
||||
doc(Streams) { "Returns a stream containing the results of applying the given *transform* function to each element and its index of the original stream" }
|
||||
body(Streams) {
|
||||
"return TransformingIndexedStream(this, transform)"
|
||||
inline(false, Sequences)
|
||||
returns(Sequences) { "Sequence<R>" }
|
||||
doc(Sequences) { "Returns a sequence containing the results of applying the given *transform* function to each element and its index of the original sequence" }
|
||||
body(Sequences) {
|
||||
"return TransformingIndexedSequence(this, transform)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ fun mapping(): List<GenericFunction> {
|
||||
"return mapTo(ArrayList<R>(), transform)"
|
||||
}
|
||||
|
||||
inline(false, Streams)
|
||||
returns(Streams) { "Stream<R>" }
|
||||
doc(Streams) { "Returns a stream containing the results of applying the given *transform* function to each element of the original stream" }
|
||||
body(Streams) {
|
||||
"return TransformingStream(this, transform)"
|
||||
inline(false, Sequences)
|
||||
returns(Sequences) { "Sequence<R>" }
|
||||
doc(Sequences) { "Returns a sequence containing the results of applying the given *transform* function to each element of the original sequence" }
|
||||
body(Sequences) {
|
||||
"return TransformingSequence(this, transform)"
|
||||
}
|
||||
include(Maps)
|
||||
}
|
||||
@@ -100,12 +100,12 @@ fun mapping(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
doc(Streams) { "Returns a stream containing the results of applying the given *transform* function to each non-null element of the original stream" }
|
||||
returns(Streams) { "Stream<R>" }
|
||||
inline(false, Streams)
|
||||
body(Streams) {
|
||||
doc(Sequences) { "Returns a sequence containing the results of applying the given *transform* function to each non-null element of the original sequence" }
|
||||
returns(Sequences) { "Sequence<R>" }
|
||||
inline(false, Sequences)
|
||||
body(Sequences) {
|
||||
"""
|
||||
return TransformingStream(FilteringStream(this, false, { it == null }) as Stream<T>, transform)
|
||||
return TransformingSequence(FilteringSequence(this, false, { it == null }) as Sequence<T>, transform)
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ fun mapping(): List<GenericFunction> {
|
||||
templates add f("flatMap(transform: (T) -> Iterable<R>)") {
|
||||
inline(true)
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
doc { "Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection" }
|
||||
typeParam("R")
|
||||
returns("List<R>")
|
||||
@@ -196,19 +196,19 @@ fun mapping(): List<GenericFunction> {
|
||||
include(Maps)
|
||||
}
|
||||
|
||||
templates add f("flatMap(transform: (T) -> Stream<R>)") {
|
||||
only(Streams)
|
||||
doc { "Returns a single stream of all elements streamed from results of *transform* function being invoked on each element of original stream" }
|
||||
templates add f("flatMap(transform: (T) -> Sequence<R>)") {
|
||||
only(Sequences)
|
||||
doc { "Returns a single sequence of all elements from results of *transform* function being invoked on each element of original sequence" }
|
||||
typeParam("R")
|
||||
returns("Stream<R>")
|
||||
returns("Sequence<R>")
|
||||
body {
|
||||
"return FlatteningStream(this, transform)"
|
||||
"return FlatteningSequence(this, transform)"
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("flatMapTo(destination: C, transform: (T) -> Iterable<R>)") {
|
||||
inline(true)
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
doc { "Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *destination*" }
|
||||
typeParam("R")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
@@ -225,11 +225,11 @@ fun mapping(): List<GenericFunction> {
|
||||
include(Maps)
|
||||
}
|
||||
|
||||
templates add f("flatMapTo(destination: C, transform: (T) -> Stream<R>)") {
|
||||
templates add f("flatMapTo(destination: C, transform: (T) -> Sequence<R>)") {
|
||||
inline(true)
|
||||
|
||||
only(Streams)
|
||||
doc { "Appends all elements yielded from results of *transform* function being invoked on each element of original stream, to the given *destination*" }
|
||||
only(Sequences)
|
||||
doc { "Appends all elements yielded from results of *transform* function being invoked on each element of original sequence, to the given *destination*" }
|
||||
typeParam("R")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
returns("C")
|
||||
|
||||
@@ -25,7 +25,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
}
|
||||
|
||||
templates add f("sort()") {
|
||||
@@ -44,7 +44,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
exclude(ArraysOfPrimitives)
|
||||
exclude(ArraysOfObjects)
|
||||
exclude(Strings)
|
||||
@@ -66,7 +66,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
only(Streams, ArraysOfObjects, ArraysOfPrimitives, Iterables)
|
||||
only(Sequences, ArraysOfObjects, ArraysOfPrimitives, Iterables)
|
||||
}
|
||||
|
||||
templates add f("sortDescending()") {
|
||||
@@ -85,7 +85,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
exclude(ArraysOfPrimitives)
|
||||
exclude(ArraysOfObjects)
|
||||
exclude(Strings)
|
||||
@@ -110,7 +110,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
exclude(ArraysOfPrimitives)
|
||||
exclude(Strings)
|
||||
}
|
||||
@@ -133,7 +133,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
only(Streams, ArraysOfObjects, ArraysOfPrimitives, Iterables)
|
||||
only(Sequences, ArraysOfObjects, ArraysOfPrimitives, Iterables)
|
||||
}
|
||||
|
||||
templates add f("sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R)") {
|
||||
@@ -155,7 +155,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
exclude(ArraysOfPrimitives)
|
||||
exclude(Strings)
|
||||
}
|
||||
@@ -175,7 +175,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
exclude(Streams)
|
||||
exclude(Sequences)
|
||||
exclude(ArraysOfPrimitives)
|
||||
exclude(Strings)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package templates
|
||||
|
||||
import templates.Family.*
|
||||
|
||||
fun sequences(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("stream()") {
|
||||
include(Maps)
|
||||
exclude(Sequences)
|
||||
deprecate { "Use sequence() instead" }
|
||||
doc { "Returns a sequence from the given collection" }
|
||||
returns("Stream<T>")
|
||||
body {
|
||||
"""
|
||||
val sequence = sequence()
|
||||
return object : Stream<T> {
|
||||
override fun iterator(): Iterator<T> {
|
||||
return sequence.iterator()
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
templates add f("sequence()") {
|
||||
include(Maps)
|
||||
exclude(Sequences)
|
||||
doc { "Returns a sequence from the given collection" }
|
||||
returns("Sequence<T>")
|
||||
body {
|
||||
"""
|
||||
return object : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> {
|
||||
return this@sequence.iterator()
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
body(Sequences) {
|
||||
"""
|
||||
return this
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
@@ -6,7 +6,7 @@ fun sets(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("toMutableSet()") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a mutable set containing all distinct elements from the given collection." }
|
||||
returns("MutableSet<T>")
|
||||
body {
|
||||
@@ -27,7 +27,7 @@ fun sets(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("distinct()") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a set containing all distinct elements from the given collection." }
|
||||
|
||||
returns("Set<T>")
|
||||
@@ -39,7 +39,7 @@ fun sets(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("union(other: Iterable<T>)") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a set containing all distinct elements from both collections." }
|
||||
returns("Set<T>")
|
||||
body {
|
||||
@@ -52,7 +52,7 @@ fun sets(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("intersect(other: Iterable<T>)") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a set containing all distinct elements from both collections." }
|
||||
returns("Set<T>")
|
||||
body {
|
||||
@@ -65,7 +65,7 @@ fun sets(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("subtract(other: Iterable<T>)") {
|
||||
exclude(Strings, Streams)
|
||||
exclude(Strings, Sequences)
|
||||
doc { "Returns a set containing all distinct elements from both collections." }
|
||||
returns("Set<T>")
|
||||
body {
|
||||
|
||||
@@ -41,7 +41,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
doc { "Returns an ArrayList of all elements" }
|
||||
returns("ArrayList<T>")
|
||||
body { "return toCollection(ArrayList<T>(collectionSizeOrDefault(10)))" }
|
||||
body(Streams) { "return toCollection(ArrayList<T>())" }
|
||||
body(Sequences) { "return toCollection(ArrayList<T>())" }
|
||||
body(Strings) { "return toCollection(ArrayList<T>(length()))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
@@ -70,7 +70,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
doc { "Returns a List containing all elements" }
|
||||
returns("List<T>")
|
||||
body { "return toCollection(ArrayList<T>(collectionSizeOrDefault(10)))" }
|
||||
body(Streams) { "return toCollection(ArrayList<T>())" }
|
||||
body(Sequences) { "return toCollection(ArrayList<T>())" }
|
||||
body(Strings) { "return toCollection(ArrayList<T>(length()))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
|
||||
@@ -102,11 +102,11 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
exclude(ArraysOfPrimitives, Strings)
|
||||
|
||||
doc(Streams) { "Returns a stream containing all elements that are instances of specified class" }
|
||||
returns(Streams) { "Stream<R>" }
|
||||
body(Streams) {
|
||||
doc(Sequences) { "Returns a sequence containing all elements that are instances of specified class" }
|
||||
returns(Sequences) { "Sequence<R>" }
|
||||
body(Sequences) {
|
||||
"""
|
||||
return FilteringStream(this, true, { klass.isInstance(it) }) as Stream<R>
|
||||
return FilteringSequence(this, true, { klass.isInstance(it) }) as Sequence<R>
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -140,13 +140,13 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
exclude(ArraysOfPrimitives, Strings)
|
||||
|
||||
doc(Streams) { "Returns a stream containing all elements that are instances of specified type parameter R" }
|
||||
returns(Streams) { "Stream<R>" }
|
||||
doc(Sequences) { "Returns a sequence containing all elements that are instances of specified type parameter R" }
|
||||
returns(Sequences) { "Sequence<R>" }
|
||||
inline(true)
|
||||
receiverAsterisk(true)
|
||||
body(Streams) {
|
||||
body(Sequences) {
|
||||
"""
|
||||
return FilteringStream(this, true, { it is R }) as Stream<R>
|
||||
return FilteringSequence(this, true, { it is R }) as Sequence<R>
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package templates
|
||||
|
||||
import templates.Family.*
|
||||
|
||||
fun streams(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("stream()") {
|
||||
include(Maps)
|
||||
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