From 4660b076876f137fe348c89332425b681937cc77 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 26 Jun 2015 00:09:38 +0300 Subject: [PATCH] StdLib cleanup: drop deprecated iterators and streams. --- libraries/stdlib/src/generated/_Aggregates.kt | 217 -------- libraries/stdlib/src/generated/_Elements.kt | 331 ------------ libraries/stdlib/src/generated/_Filtering.kt | 95 ---- libraries/stdlib/src/generated/_Generators.kt | 68 +-- libraries/stdlib/src/generated/_Guards.kt | 9 - libraries/stdlib/src/generated/_Mapping.kt | 131 ----- libraries/stdlib/src/generated/_Numeric.kt | 192 ------- libraries/stdlib/src/generated/_Ordering.kt | 23 - libraries/stdlib/src/generated/_Sequences.kt | 174 ------- libraries/stdlib/src/generated/_Sets.kt | 31 -- libraries/stdlib/src/generated/_Snapshots.kt | 94 ---- libraries/stdlib/src/generated/_SpecialJVM.kt | 38 -- libraries/stdlib/src/generated/_Strings.kt | 33 -- .../kotlin/collections/MutableCollections.kt | 16 - .../src/kotlin/collections/Operations.kt | 8 - .../stdlib/src/kotlin/collections/Sequence.kt | 82 +-- .../kotlin/deprecated/DeprecatedIterators.kt | 225 -------- .../deprecated/DeprecatedIteratorsJVM.kt | 23 - .../src/kotlin/deprecated/_Iterators.kt | 492 ------------------ libraries/stdlib/src/kotlin/text/Strings.kt | 5 - .../kotlin-stdlib-gen/src/templates/Engine.kt | 18 - .../src/templates/Generators.kt | 2 +- .../src/templates/Sequence.kt | 20 - 23 files changed, 7 insertions(+), 2320 deletions(-) delete mode 100644 libraries/stdlib/src/kotlin/deprecated/DeprecatedIterators.kt delete mode 100644 libraries/stdlib/src/kotlin/deprecated/DeprecatedIteratorsJVM.kt delete mode 100644 libraries/stdlib/src/kotlin/deprecated/_Iterators.kt diff --git a/libraries/stdlib/src/generated/_Aggregates.kt b/libraries/stdlib/src/generated/_Aggregates.kt index 5fe47d703a6..6dccea3be3b 100644 --- a/libraries/stdlib/src/generated/_Aggregates.kt +++ b/libraries/stdlib/src/generated/_Aggregates.kt @@ -106,16 +106,6 @@ public inline fun Sequence.all(predicate: (T) -> Boolean): Boolean { return true } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns `true` if all elements match the given [predicate]. - */ -public inline fun Stream.all(predicate: (T) -> Boolean): Boolean { - for (element in this) if (!predicate(element)) return false - return true -} - /** * Returns `true` if all elements match the given [predicate]. */ @@ -220,16 +210,6 @@ public fun Sequence.any(): Boolean { return false } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns `true` if collection has at least one element. - */ -public fun Stream.any(): Boolean { - for (element in this) return true - return false -} - /** * Returns `true` if collection has at least one element. */ @@ -334,16 +314,6 @@ public inline fun Sequence.any(predicate: (T) -> Boolean): Boolean { return false } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns `true` if at least one element matches the given [predicate]. - */ -public inline fun Stream.any(predicate: (T) -> Boolean): Boolean { - for (element in this) if (predicate(element)) return true - return false -} - /** * Returns `true` if at least one element matches the given [predicate]. */ @@ -447,17 +417,6 @@ public fun Sequence.count(): Int { return count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the number of elements in this collection. - */ -public fun Stream.count(): Int { - var count = 0 - for (element in this) count++ - return count -} - /** * Returns the length of this string. */ @@ -573,17 +532,6 @@ public inline fun Sequence.count(predicate: (T) -> Boolean): Int { return count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the number of elements matching the given [predicate]. - */ -public inline fun Stream.count(predicate: (T) -> Boolean): Int { - var count = 0 - for (element in this) if (predicate(element)) count++ - return count -} - /** * Returns the number of elements matching the given [predicate]. */ @@ -692,17 +640,6 @@ public inline fun Sequence.fold(initial: R, operation: (R, T) -> R): R return accumulator } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element. - */ -public inline fun Stream.fold(initial: R, operation: (R, T) -> R): R { - var accumulator = initial - for (element in this) accumulator = operation(accumulator, element) - return accumulator -} - /** * Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element. */ @@ -928,15 +865,6 @@ public inline fun Sequence.forEach(operation: (T) -> Unit): Unit { for (element in this) operation(element) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Performs the given [operation] on each element. - */ -public inline fun Stream.forEach(operation: (T) -> Unit): Unit { - for (element in this) operation(element) -} - /** * Performs the given [operation] on each element. */ @@ -1032,16 +960,6 @@ public inline fun Sequence.forEachIndexed(operation: (Int, T) -> Unit): U for (item in this) operation(index++, item) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Performs the given [operation] on each element, providing sequential index with the element. - */ -public inline fun Stream.forEachIndexed(operation: (Int, T) -> Unit): Unit { - var index = 0 - for (item in this) operation(index++, item) -} - /** * Performs the given [operation] on each element, providing sequential index with the element. */ @@ -1182,22 +1100,6 @@ public fun > Sequence.max(): T? { return max } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the largest element or `null` if there are no elements. - */ -public fun > Stream.max(): T? { - val iterator = iterator() - if (!iterator.hasNext()) return null - var max = iterator.next() - while (iterator.hasNext()) { - val e = iterator.next() - if (max < e) max = e - } - return max -} - /** * Returns the largest element or `null` if there are no elements. */ @@ -1412,27 +1314,6 @@ public inline fun , T : Any> Sequence.maxBy(f: (T) -> R): T return maxElem } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the first element yielding the largest value of the given function or `null` if there are no elements. - */ -public inline fun , T : Any> Stream.maxBy(f: (T) -> R): T? { - val iterator = iterator() - if (!iterator.hasNext()) return null - var maxElem = iterator.next() - var maxValue = f(maxElem) - while (iterator.hasNext()) { - val e = iterator.next() - val v = f(e) - if (maxValue < v) { - maxElem = e - maxValue = v - } - } - return maxElem -} - /** * Returns the first element yielding the largest value of the given function or `null` if there are no elements. */ @@ -1603,22 +1484,6 @@ public fun > Sequence.min(): T? { return min } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the smallest element or `null` if there are no elements. - */ -public fun > Stream.min(): T? { - val iterator = iterator() - if (!iterator.hasNext()) return null - var min = iterator.next() - while (iterator.hasNext()) { - val e = iterator.next() - if (min > e) min = e - } - return min -} - /** * Returns the smallest element or `null` if there are no elements. */ @@ -1833,27 +1698,6 @@ public inline fun , T : Any> Sequence.minBy(f: (T) -> R): T return minElem } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the first element yielding the smallest value of the given function or `null` if there are no elements. - */ -public inline fun , T : Any> Stream.minBy(f: (T) -> R): T? { - val iterator = iterator() - if (!iterator.hasNext()) return null - var minElem = iterator.next() - var minValue = f(minElem) - while (iterator.hasNext()) { - val e = iterator.next() - val v = f(e) - if (minValue > v) { - minElem = e - minValue = v - } - } - return minElem -} - /** * Returns the first element yielding the smallest value of the given function or `null` if there are no elements. */ @@ -1988,16 +1832,6 @@ public fun Sequence.none(): Boolean { return true } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns `true` if collection has no elements. - */ -public fun Stream.none(): Boolean { - for (element in this) return false - return true -} - /** * Returns `true` if collection has no elements. */ @@ -2102,16 +1936,6 @@ public inline fun Sequence.none(predicate: (T) -> Boolean): Boolean { return true } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns `true` if no elements match the given [predicate]. - */ -public inline fun Stream.none(predicate: (T) -> Boolean): Boolean { - for (element in this) if (predicate(element)) return false - return true -} - /** * Returns `true` if no elements match the given [predicate]. */ @@ -2159,21 +1983,6 @@ public inline fun Sequence.reduce(operation: (S, T) -> S): S { return accumulator } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element. - */ -public inline fun Stream.reduce(operation: (S, T) -> S): S { - val iterator = this.iterator() - if (!iterator.hasNext()) throw UnsupportedOperationException("Empty iterable can't be reduced.") - var accumulator: S = iterator.next() - while (iterator.hasNext()) { - accumulator = operation(accumulator, iterator.next()) - } - return accumulator -} - /** * Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element. */ @@ -2555,19 +2364,6 @@ public inline fun Sequence.sumBy(transform: (T) -> Int): Int { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all values produced by [transform] function from elements in the collection. - */ -public inline fun Stream.sumBy(transform: (T) -> Int): Int { - var sum: Int = 0 - for (element in this) { - sum += transform(element) - } - return sum -} - /** * Returns the sum of all values produced by [transform] function from characters in the string. */ @@ -2700,19 +2496,6 @@ public inline fun Sequence.sumByDouble(transform: (T) -> Double): Double return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all values produced by [transform] function from elements in the collection. - */ -public inline fun Stream.sumByDouble(transform: (T) -> Double): Double { - var sum: Double = 0.0 - for (element in this) { - sum += transform(element) - } - return sum -} - /** * Returns the sum of all values produced by [transform] function from characters in the string. */ diff --git a/libraries/stdlib/src/generated/_Elements.kt b/libraries/stdlib/src/generated/_Elements.kt index 3a293656c3c..d57c2d248ce 100644 --- a/libraries/stdlib/src/generated/_Elements.kt +++ b/libraries/stdlib/src/generated/_Elements.kt @@ -441,17 +441,6 @@ public fun Sequence.contains(element: T): Boolean { return indexOf(element) >= 0 } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns `true` if [element] is found in the collection. - */ -public fun Stream.contains(element: T): Boolean { - if (this is Collection<*>) - return contains(element) - return indexOf(element) >= 0 -} - /** * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection. */ @@ -538,15 +527,6 @@ public fun Sequence.elementAt(index: Int): T { return elementAtOrElse(index) { throw IndexOutOfBoundsException("Sequence doesn't contain element at index $index.") } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection. - */ -public fun Stream.elementAt(index: Int): T { - return elementAtOrElse(index) { throw IndexOutOfBoundsException("Stream doesn't contain element at index $index.") } -} - /** * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection. */ @@ -658,24 +638,6 @@ public inline fun Sequence.elementAtOrElse(index: Int, defaultValue: (Int return defaultValue(index) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection. - */ -public inline fun Stream.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T { - if (index < 0) - return defaultValue(index) - val iterator = iterator() - var count = 0 - while (iterator.hasNext()) { - val element = iterator.next() - if (index == count++) - return element - } - return defaultValue(index) -} - /** * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection. */ @@ -787,24 +749,6 @@ public fun Sequence.elementAtOrNull(index: Int): T? { return null } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection. - */ -public fun Stream.elementAtOrNull(index: Int): T? { - if (index < 0) - return null - val iterator = iterator() - var count = 0 - while (iterator.hasNext()) { - val element = iterator.next() - if (index == count++) - return element - } - return null -} - /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection. */ @@ -954,29 +898,6 @@ public fun Sequence.first(): T { } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns first element. - * @throws [NoSuchElementException] if the collection is empty. - */ -public fun Stream.first(): T { - when (this) { - is List<*> -> { - if (isEmpty()) - throw NoSuchElementException("Collection is empty.") - else - return this[0] as T - } - else -> { - val iterator = iterator() - if (!iterator.hasNext()) - throw NoSuchElementException("Collection is empty.") - return iterator.next() - } - } -} - /** * Returns first character. * @throws [NoSuchElementException] if the string is empty. @@ -1086,17 +1007,6 @@ public inline fun Sequence.first(predicate: (T) -> Boolean): T { throw NoSuchElementException("No element matching predicate was found.") } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the first element matching the given [predicate]. - * @throws [NoSuchElementException] if no such element is found. - */ -public inline fun Stream.first(predicate: (T) -> Boolean): T { - for (element in this) if (predicate(element)) return element - throw NoSuchElementException("No element matching predicate was found.") -} - /** * Returns the first character matching the given [predicate]. * @throws [NoSuchElementException] if no such character is found. @@ -1216,28 +1126,6 @@ public fun Sequence.firstOrNull(): T? { } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the first element, or `null` if the collection is empty. - */ -public fun Stream.firstOrNull(): T? { - when (this) { - is List<*> -> { - if (isEmpty()) - return null - else - return this[0] as T - } - else -> { - val iterator = iterator() - if (!iterator.hasNext()) - return null - return iterator.next() - } - } -} - /** * Returns the first character, or `null` if string is empty. */ @@ -1333,16 +1221,6 @@ public inline fun Sequence.firstOrNull(predicate: (T) -> Boolean): T? { return null } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the first element matching the given [predicate], or `null` if element was not found. - */ -public inline fun Stream.firstOrNull(predicate: (T) -> Boolean): T? { - for (element in this) if (predicate(element)) return element - return null -} - /** * Returns the first character matching the given [predicate], or `null` if character was not found. */ @@ -1493,21 +1371,6 @@ public fun Sequence.indexOf(element: T): Int { return -1 } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns first index of [element], or -1 if the collection does not contain element. - */ -public fun Stream.indexOf(element: T): Int { - var index = 0 - for (item in this) { - if (element == item) - return index - index++ - } - return -1 -} - /** * Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element. */ @@ -1654,21 +1517,6 @@ public inline fun Sequence.indexOfFirst(predicate: (T) -> Boolean): Int { return -1 } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element. - */ -public inline fun Stream.indexOfFirst(predicate: (T) -> Boolean): Int { - var index = 0 - for (item in this) { - if (predicate(item)) - return index - index++ - } - return -1 -} - /** * Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element. */ @@ -1829,22 +1677,6 @@ public inline fun Sequence.indexOfLast(predicate: (T) -> Boolean): Int { return lastIndex } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element. - */ -public inline fun Stream.indexOfLast(predicate: (T) -> Boolean): Int { - var lastIndex = -1 - var index = 0 - for (item in this) { - if (predicate(item)) - lastIndex = index - index++ - } - return lastIndex -} - /** * Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element. */ @@ -1995,22 +1827,6 @@ public fun Sequence.last(): T { return last } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the last element. - * @throws [NoSuchElementException] if the collection is empty. - */ -public fun Stream.last(): T { - val iterator = iterator() - if (!iterator.hasNext()) - throw NoSuchElementException("Collection is empty.") - var last = iterator.next() - while (iterator.hasNext()) - last = iterator.next() - return last -} - /** * "Returns the last character. * @throws [NoSuchElementException] if the string is empty. @@ -2177,25 +1993,6 @@ public inline fun Sequence.last(predicate: (T) -> Boolean): T { return last as T } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the last element matching the given [predicate]. - * @throws [NoSuchElementException] if no such element is found. - */ -public inline fun Stream.last(predicate: (T) -> Boolean): T { - var last: T? = null - var found = false - for (element in this) { - if (predicate(element)) { - last = element - found = true - } - } - if (!found) throw NoSuchElementException("Collection doesn't contain any element matching the predicate.") - return last as T -} - /** * "Returns the last character matching the given [predicate]. * @throws [NoSuchElementException] if no such character is found. @@ -2357,22 +2154,6 @@ public fun Sequence.lastIndexOf(element: T): Int { return lastIndex } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns last index of [element], or -1 if the collection does not contain element. - */ -public fun Stream.lastIndexOf(element: T): Int { - var lastIndex = -1 - var index = 0 - for (item in this) { - if (element == item) - lastIndex = index - index++ - } - return lastIndex -} - /** * Returns the last element, or `null` if the collection is empty. */ @@ -2474,21 +2255,6 @@ public fun Sequence.lastOrNull(): T? { return last } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the last element, or `null` if the collection is empty. - */ -public fun Stream.lastOrNull(): T? { - val iterator = iterator() - if (!iterator.hasNext()) - return null - var last = iterator.next() - while (iterator.hasNext()) - last = iterator.next() - return last -} - /** * Returns the last character, or `null` if the string is empty. */ @@ -2634,21 +2400,6 @@ public inline fun Sequence.lastOrNull(predicate: (T) -> Boolean): T? { return last } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the last element matching the given [predicate], or `null` if no such element was found. - */ -public inline fun Stream.lastOrNull(predicate: (T) -> Boolean): T? { - var last: T? = null - for (element in this) { - if (predicate(element)) { - last = element - } - } - return last -} - /** * Returns the last character matching the given [predicate], or `null` if no such character was found. */ @@ -2816,30 +2567,6 @@ public fun Sequence.single(): T { } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the single element, or throws an exception if the collection is empty or has more than one element. - */ -public fun Stream.single(): T { - when (this) { - is List<*> -> return when (size()) { - 0 -> throw NoSuchElementException("Collection is empty.") - 1 -> this[0] as T - else -> throw IllegalArgumentException("Collection has more than one element.") - } - else -> { - val iterator = iterator() - if (!iterator.hasNext()) - throw NoSuchElementException("Collection is empty.") - var single = iterator.next() - if (iterator.hasNext()) - throw IllegalArgumentException("Collection has more than one element.") - return single - } - } -} - /** * Returns the single character, or throws an exception if the string is empty or has more than one character. */ @@ -3038,25 +2765,6 @@ public inline fun Sequence.single(predicate: (T) -> Boolean): T { return single as T } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element. - */ -public inline fun Stream.single(predicate: (T) -> Boolean): T { - var single: T? = null - var found = false - for (element in this) { - if (predicate(element)) { - if (found) throw IllegalArgumentException("Collection contains more than one matching element.") - single = element - found = true - } - } - if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.") - return single as T -} - /** * Returns the single character matching the given [predicate], or throws exception if there is no or more than one matching character. */ @@ -3180,26 +2888,6 @@ public fun Sequence.singleOrNull(): T? { } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns single element, or `null` if the collection is empty or has more than one element. - */ -public fun Stream.singleOrNull(): T? { - when (this) { - is List<*> -> return if (size() == 1) this[0] as T else null - else -> { - val iterator = iterator() - if (!iterator.hasNext()) - return null - var single = iterator.next() - if (iterator.hasNext()) - return null - return single - } - } -} - /** * Returns the single character, or `null` if the string is empty or has more than one character. */ @@ -3394,25 +3082,6 @@ public inline fun Sequence.singleOrNull(predicate: (T) -> Boolean): T? { return single } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found. - */ -public inline fun Stream.singleOrNull(predicate: (T) -> Boolean): T? { - var single: T? = null - var found = false - for (element in this) { - if (predicate(element)) { - if (found) return null - single = element - found = true - } - } - if (!found) return null - return single -} - /** * Returns the single character matching the given [predicate], or `null` if character was not found or more than one character was found. */ diff --git a/libraries/stdlib/src/generated/_Filtering.kt b/libraries/stdlib/src/generated/_Filtering.kt index b2a902441cf..a478e25b808 100644 --- a/libraries/stdlib/src/generated/_Filtering.kt +++ b/libraries/stdlib/src/generated/_Filtering.kt @@ -191,16 +191,6 @@ public fun Sequence.drop(n: Int): Sequence { return if (n == 0) this else DropSequence(this, n) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements except first [n] elements. - */ -public fun Stream.drop(n: Int): Stream { - require(n >= 0, { "Requested element count $n is less than zero." }) - return if (n == 0) this else DropStream(this, n) -} - /** * Returns a string with the first [n] characters removed. */ @@ -590,15 +580,6 @@ public fun Sequence.dropWhile(predicate: (T) -> Boolean): Sequence { return DropWhileSequence(this, predicate) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements except first elements that satisfy the given [predicate]. - */ -public fun Stream.dropWhile(predicate: (T) -> Boolean): Stream { - return DropWhileStream(this, predicate) -} - /** * Returns a string containing all characters except first characters that satisfy the given [predicate]. */ @@ -683,15 +664,6 @@ public fun Sequence.filter(predicate: (T) -> Boolean): Sequence { return FilteringSequence(this, true, predicate) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements matching the given [predicate]. - */ -public fun Stream.filter(predicate: (T) -> Boolean): Stream { - return FilteringStream(this, true, predicate) -} - /** * Returns a string containing only those characters from the original string that match the given [predicate]. */ @@ -776,15 +748,6 @@ public fun Sequence.filterNot(predicate: (T) -> Boolean): Sequence { return FilteringSequence(this, false, predicate) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements not matching the given [predicate]. - */ -public fun Stream.filterNot(predicate: (T) -> Boolean): Stream { - return FilteringStream(this, false, predicate) -} - /** * Returns a string containing only those characters from the original string that do not match the given [predicate]. */ @@ -813,15 +776,6 @@ public fun Sequence.filterNotNull(): Sequence { return filterNot { it == null } as Sequence } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements that are not `null`. - */ -public fun Stream.filterNotNull(): Stream { - return filterNot { it == null } as Stream -} - /** * Appends all elements that are not `null` to the given [destination]. */ @@ -846,16 +800,6 @@ public fun , T : Any> Sequence.filterNotNullTo(d return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements that are not `null` to the given [destination]. - */ -public fun , T : Any> Stream.filterNotNullTo(destination: C): C { - for (element in this) if (element != null) destination.add(element) - return destination -} - /** * Appends all elements not matching the given [predicate] to the given [destination]. */ @@ -944,16 +888,6 @@ public inline fun > Sequence.filterNotTo(desti return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements not matching the given [predicate] to the given [destination]. - */ -public inline fun > Stream.filterNotTo(destination: C, predicate: (T) -> Boolean): C { - for (element in this) if (!predicate(element)) destination.add(element) - return destination -} - /** * Appends all characters not matching the given [predicate] to the given [destination]. */ @@ -1050,16 +984,6 @@ public inline fun > Sequence.filterTo(destinat return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements matching the given [predicate] into the given [destination]. - */ -public inline fun > Stream.filterTo(destination: C, predicate: (T) -> Boolean): C { - for (element in this) if (predicate(element)) destination.add(element) - return destination -} - /** * Appends all characters matching the given [predicate] to the given [destination]. */ @@ -1370,16 +1294,6 @@ public fun Sequence.take(n: Int): Sequence { return if (n == 0) emptySequence() else TakeSequence(this, n) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing first [n] elements. - */ -public fun Stream.take(n: Int): Stream { - require(n >= 0, { "Requested element count $n is less than zero." }) - return if (n == 0) emptyStream() else TakeStream(this, n) -} - /** * Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter. */ @@ -1806,15 +1720,6 @@ public fun Sequence.takeWhile(predicate: (T) -> Boolean): Sequence { return TakeWhileSequence(this, predicate) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing first elements satisfying the given [predicate]. - */ -public fun Stream.takeWhile(predicate: (T) -> Boolean): Stream { - return TakeWhileStream(this, predicate) -} - /** * Returns a string containing the first characters that satisfy the given [predicate]. */ diff --git a/libraries/stdlib/src/generated/_Generators.kt b/libraries/stdlib/src/generated/_Generators.kt index ab12fec0211..899edd8e78c 100644 --- a/libraries/stdlib/src/generated/_Generators.kt +++ b/libraries/stdlib/src/generated/_Generators.kt @@ -381,15 +381,6 @@ public fun Sequence.merge(sequence: Sequence, transform: (T, R) return MergingSequence(this, sequence, transform) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream of values built from elements of both collections with same indexes using provided [transform]. Resulting stream has length of shortest input streams. - */ -public fun Stream.merge(stream: Stream, transform: (T, R) -> V): Stream { - return MergingStream(this, stream, transform) -} - /** * Splits original collection into pair of collections, * where *first* collection contains elements for which [predicate] yielded `true`, @@ -588,26 +579,6 @@ public inline fun Sequence.partition(predicate: (T) -> Boolean): Pair and respective functions") -/** - * Splits original collection into pair of collections, - * where *first* collection contains elements for which [predicate] yielded `true`, - * while *second* collection contains elements for which [predicate] yielded `false`. - */ -public inline fun Stream.partition(predicate: (T) -> Boolean): Pair, List> { - val first = ArrayList() - val second = ArrayList() - for (element in this) { - if (predicate(element)) { - first.add(element) - } else { - second.add(element) - } - } - return Pair(first, second) -} - /** * Splits original collection into pair of collections, * where *first* collection contains elements for which [predicate] yielded `true`, @@ -830,16 +801,7 @@ public fun Iterable.plus(collection: Iterable): List { * Returns a sequence containing all elements of original sequence and then all elements of the given [collection]. */ public fun Sequence.plus(collection: Iterable): Sequence { - return sequenceOf(this, collection.sequence()).flatten() -} - - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements of original stream and then all elements of the given [collection]. - */ -public fun Stream.plus(collection: Iterable): Stream { - return streamOf(this, collection.stream()).flatten() + return sequenceOf(this, collection.asSequence()).flatten() } /** @@ -949,15 +911,6 @@ public fun Sequence.plus(element: T): Sequence { return sequenceOf(this, sequenceOf(element)).flatten() } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements of original stream and then the given [element]. - */ -public fun Stream.plus(element: T): Stream { - return streamOf(this, streamOf(element)).flatten() -} - /** * Returns a sequence containing all elements of original sequence and then all elements of the given [sequence]. */ @@ -965,15 +918,6 @@ public fun Sequence.plus(sequence: Sequence): Sequence { return sequenceOf(this, sequence).flatten() } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements of original stream and then all elements of the given [stream]. - */ -public fun Stream.plus(stream: Stream): Stream { - return streamOf(this, stream).flatten() -} - /** * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection. */ @@ -1191,13 +1135,3 @@ public fun Sequence.zip(sequence: Sequence): Sequence> { return MergingSequence(this, sequence) { t1, t2 -> t1 to t2 } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream of pairs built from elements of both collections with same indexes. - * Resulting stream has length of shortest input streams. - */ -public fun Stream.zip(stream: Stream): Stream> { - return MergingStream(this, stream) { t1, t2 -> t1 to t2 } -} - diff --git a/libraries/stdlib/src/generated/_Guards.kt b/libraries/stdlib/src/generated/_Guards.kt index 8f55e8ab638..5c6af1b4d6b 100644 --- a/libraries/stdlib/src/generated/_Guards.kt +++ b/libraries/stdlib/src/generated/_Guards.kt @@ -53,12 +53,3 @@ public fun Sequence.requireNoNulls(): Sequence { return map { it ?: throw IllegalArgumentException("null element found in $this.") } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements. - */ -public fun Stream.requireNoNulls(): Stream { - return map { it ?: throw IllegalArgumentException("null element found in $this.") } -} - diff --git a/libraries/stdlib/src/generated/_Mapping.kt b/libraries/stdlib/src/generated/_Mapping.kt index 9807b37eb55..61ebace358f 100644 --- a/libraries/stdlib/src/generated/_Mapping.kt +++ b/libraries/stdlib/src/generated/_Mapping.kt @@ -101,15 +101,6 @@ public fun Sequence.flatMap(transform: (T) -> Sequence): Sequence and respective functions") -/** - * Returns a single stream of all elements from results of [transform] function being invoked on each element of original stream. - */ -public fun Stream.flatMap(transform: (T) -> Stream): Stream { - return FlatteningStream(this, transform) -} - /** * Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination]. */ @@ -253,19 +244,6 @@ public inline fun > Sequence.flatMapTo(dest return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements yielded from results of [transform] function being invoked on each element of original stream, to the given [destination]. - */ -public inline fun > Stream.flatMapTo(destination: C, transform: (T) -> Stream): C { - for (element in this) { - val list = transform(element) - destination.addAll(list) - } - return destination -} - /** * Returns a map of the elements in original collection grouped by the result of given [toKey] function. */ @@ -343,15 +321,6 @@ public inline fun Sequence.groupBy(toKey: (T) -> K): Map> { return groupByTo(LinkedHashMap>(), toKey) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a map of the elements in original collection grouped by the result of given [toKey] function. - */ -public inline fun Stream.groupBy(toKey: (T) -> K): Map> { - return groupByTo(LinkedHashMap>(), toKey) -} - /** * Returns a map of the elements in original collection grouped by the result of given [toKey] function. */ @@ -491,20 +460,6 @@ public inline fun Sequence.groupByTo(map: MutableMap return map } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends elements from original collection grouped by the result of given [toKey] function to the given [map]. - */ -public inline fun Stream.groupByTo(map: MutableMap>, toKey: (T) -> K): Map> { - for (element in this) { - val key = toKey(element) - val list = map.getOrPut(key) { ArrayList() } - list.add(element) - } - return map -} - /** * Appends elements from original collection grouped by the result of given [toKey] function to the given [map]. */ @@ -601,15 +556,6 @@ public fun Sequence.map(transform: (T) -> R): Sequence { return TransformingSequence(this, transform) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing the results of applying the given [transform] function to each element of the original stream. - */ -public fun Stream.map(transform: (T) -> R): Stream { - return TransformingStream(this, transform) -} - /** * Returns a list containing the results of applying the given [transform] function to each element of the original collection. */ @@ -694,15 +640,6 @@ public fun Sequence.mapIndexed(transform: (Int, T) -> R): Sequence return TransformingIndexedSequence(this, transform) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing the results of applying the given [transform] function to each element and its index of the original stream. - */ -public fun Stream.mapIndexed(transform: (Int, T) -> R): Stream { - return TransformingIndexedStream(this, transform) -} - /** * Returns a list containing the results of applying the given [transform] function to each element and its index of the original collection. */ @@ -842,19 +779,6 @@ public inline fun > Sequence.mapIndexedTo(d return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends transformed elements and their indices of the original collection using the given [transform] function - * to the given [destination]. - */ -public inline fun > Stream.mapIndexedTo(destination: C, transform: (Int, T) -> R): C { - var index = 0 - for (item in this) - destination.add(transform(index++, item)) - return destination -} - /** * Appends transformed elements and their indices of the original collection using the given [transform] function * to the given [destination]. @@ -887,15 +811,6 @@ public fun Sequence.mapNotNull(transform: (T) -> R): Sequence, transform) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing the results of applying the given [transform] function to each non-null element of the original stream. - */ -public fun Stream.mapNotNull(transform: (T) -> R): Stream { - return TransformingStream(FilteringStream(this, false, { it == null }) as Stream, transform) -} - /** * Appends transformed non-null elements of original collection using the given [transform] function * to the given [destination]. @@ -935,21 +850,6 @@ public inline fun > Sequence.mapNotN return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends transformed non-null elements of original collection using the given [transform] function - * to the given [destination]. - */ -public inline fun > Stream.mapNotNullTo(destination: C, transform: (T) -> R): C { - for (element in this) { - if (element != null) { - destination.add(transform(element)) - } - } - return destination -} - /** * Appends transformed elements of the original collection using the given [transform] function * to the given [destination]. @@ -1070,18 +970,6 @@ public inline fun > Sequence.mapTo(destinat return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends transformed elements of the original collection using the given [transform] function - * to the given [destination]. - */ -public inline fun > Stream.mapTo(destination: C, transform: (T) -> R): C { - for (item in this) - destination.add(transform(item)) - return destination -} - /** * Appends transformed elements of the original collection using the given [transform] function * to the given [destination]. @@ -1169,15 +1057,6 @@ public fun Sequence.withIndex(): Sequence> { return IndexingSequence(this) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream of [IndexedValue] for each element of the original stream. - */ -public fun Stream.withIndex(): Stream> { - return IndexingStream(this) -} - /** * Returns a lazy [Iterable] of [IndexedValue] for each element of the original collection. */ @@ -1284,16 +1163,6 @@ public fun Sequence.withIndices(): Sequence> { return TransformingSequence(this, { index++ to it }) } - -/** - * Returns a stream containing pairs of each element of the original collection and their index. - */ -deprecated("Use withIndex() instead.") -public fun Stream.withIndices(): Stream> { - var index = 0 - return TransformingStream(this, { index++ to it }) -} - /** * Returns a list containing pairs of each element of the original collection and their index. */ diff --git a/libraries/stdlib/src/generated/_Numeric.kt b/libraries/stdlib/src/generated/_Numeric.kt index 06dd2884a75..df318f6ca04 100644 --- a/libraries/stdlib/src/generated/_Numeric.kt +++ b/libraries/stdlib/src/generated/_Numeric.kt @@ -40,23 +40,6 @@ public fun Sequence.average(): Double { return if (count == 0) 0.0 else sum / count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an average value of elements in the collection. - */ -platformName("averageOfInt") -public fun Stream.average(): Double { - val iterator = iterator() - var sum: Double = 0.0 - var count: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - count += 1 - } - return if (count == 0) 0.0 else sum / count -} - /** * Returns an average value of elements in the collection. */ @@ -116,23 +99,6 @@ public fun Sequence.average(): Double { return if (count == 0) 0.0 else sum / count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an average value of elements in the collection. - */ -platformName("averageOfLong") -public fun Stream.average(): Double { - val iterator = iterator() - var sum: Double = 0.0 - var count: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - count += 1 - } - return if (count == 0) 0.0 else sum / count -} - /** * Returns an average value of elements in the collection. */ @@ -192,23 +158,6 @@ public fun Sequence.average(): Double { return if (count == 0) 0.0 else sum / count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an average value of elements in the collection. - */ -platformName("averageOfByte") -public fun Stream.average(): Double { - val iterator = iterator() - var sum: Double = 0.0 - var count: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - count += 1 - } - return if (count == 0) 0.0 else sum / count -} - /** * Returns an average value of elements in the collection. */ @@ -268,23 +217,6 @@ public fun Sequence.average(): Double { return if (count == 0) 0.0 else sum / count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an average value of elements in the collection. - */ -platformName("averageOfShort") -public fun Stream.average(): Double { - val iterator = iterator() - var sum: Double = 0.0 - var count: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - count += 1 - } - return if (count == 0) 0.0 else sum / count -} - /** * Returns an average value of elements in the collection. */ @@ -344,23 +276,6 @@ public fun Sequence.average(): Double { return if (count == 0) 0.0 else sum / count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an average value of elements in the collection. - */ -platformName("averageOfDouble") -public fun Stream.average(): Double { - val iterator = iterator() - var sum: Double = 0.0 - var count: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - count += 1 - } - return if (count == 0) 0.0 else sum / count -} - /** * Returns an average value of elements in the collection. */ @@ -420,23 +335,6 @@ public fun Sequence.average(): Double { return if (count == 0) 0.0 else sum / count } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an average value of elements in the collection. - */ -platformName("averageOfFloat") -public fun Stream.average(): Double { - val iterator = iterator() - var sum: Double = 0.0 - var count: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - count += 1 - } - return if (count == 0) 0.0 else sum / count -} - /** * Returns an average value of elements in the collection. */ @@ -492,21 +390,6 @@ public fun Sequence.sum(): Int { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all elements in the collection. - */ -platformName("sumOfInt") -public fun Stream.sum(): Int { - val iterator = iterator() - var sum: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - } - return sum -} - /** * Returns the sum of all elements in the collection. */ @@ -558,21 +441,6 @@ public fun Sequence.sum(): Long { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all elements in the collection. - */ -platformName("sumOfLong") -public fun Stream.sum(): Long { - val iterator = iterator() - var sum: Long = 0 - while (iterator.hasNext()) { - sum += iterator.next() - } - return sum -} - /** * Returns the sum of all elements in the collection. */ @@ -624,21 +492,6 @@ public fun Sequence.sum(): Int { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all elements in the collection. - */ -platformName("sumOfByte") -public fun Stream.sum(): Int { - val iterator = iterator() - var sum: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - } - return sum -} - /** * Returns the sum of all elements in the collection. */ @@ -690,21 +543,6 @@ public fun Sequence.sum(): Int { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all elements in the collection. - */ -platformName("sumOfShort") -public fun Stream.sum(): Int { - val iterator = iterator() - var sum: Int = 0 - while (iterator.hasNext()) { - sum += iterator.next() - } - return sum -} - /** * Returns the sum of all elements in the collection. */ @@ -756,21 +594,6 @@ public fun Sequence.sum(): Double { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all elements in the collection. - */ -platformName("sumOfDouble") -public fun Stream.sum(): Double { - val iterator = iterator() - var sum: Double = 0.0 - while (iterator.hasNext()) { - sum += iterator.next() - } - return sum -} - /** * Returns the sum of all elements in the collection. */ @@ -822,21 +645,6 @@ public fun Sequence.sum(): Float { return sum } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns the sum of all elements in the collection. - */ -platformName("sumOfFloat") -public fun Stream.sum(): Float { - val iterator = iterator() - var sum: Float = 0.0f - while (iterator.hasNext()) { - sum += iterator.next() - } - return sum -} - /** * Returns the sum of all elements in the collection. */ diff --git a/libraries/stdlib/src/generated/_Ordering.kt b/libraries/stdlib/src/generated/_Ordering.kt index 5ec4aa3ecc2..2a09ac98eb7 100644 --- a/libraries/stdlib/src/generated/_Ordering.kt +++ b/libraries/stdlib/src/generated/_Ordering.kt @@ -292,17 +292,6 @@ public fun > Sequence.toSortedList(): List { return sortedList } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a sorted list of all elements. - */ -public fun > Stream.toSortedList(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList -} - /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ @@ -413,15 +402,3 @@ public fun > Sequence.toSortedListBy(order: (T) -> V): L return sortedList } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a sorted list of all elements, ordered by results of specified [order] function. - */ -public fun > Stream.toSortedListBy(order: (T) -> V): List { - val sortedList = toArrayList() - val sortBy: Comparator = compareBy(order) - java.util.Collections.sort(sortedList, sortBy) - return sortedList -} - diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index 835eca74b85..d2e1b314b20 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -138,15 +138,6 @@ public fun Sequence.asSequence(): Sequence { return this } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream from the given collection. - */ -public fun Stream.asStream(): Stream { - return this -} - /** * Returns a sequence from the given collection. */ @@ -254,15 +245,6 @@ public fun Sequence.sequence(): Sequence { return this } - -/** - * Returns a stream from the given collection - */ -deprecated("Use asStream() instead", ReplaceWith("asStream()")) -public fun Stream.stream(): Stream { - return this -} - /** * Returns a sequence from the given collection */ @@ -271,159 +253,3 @@ public fun String.sequence(): Sequence { return asSequence() } -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun Array.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun BooleanArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun ByteArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun CharArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun DoubleArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun FloatArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun IntArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun LongArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun ShortArray.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun Iterable.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun Map.stream(): Stream> { - val sequence = asSequence() - return object : Stream> { - override fun iterator(): Iterator> { - return sequence.iterator() - } - } -} - -/** - * Returns a sequence from the given collection - */ -deprecated("Use asSequence() instead", ReplaceWith("asSequence()")) -public fun String.stream(): Stream { - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } -} - diff --git a/libraries/stdlib/src/generated/_Sets.kt b/libraries/stdlib/src/generated/_Sets.kt index 530ae0d9a56..d22ee123416 100644 --- a/libraries/stdlib/src/generated/_Sets.kt +++ b/libraries/stdlib/src/generated/_Sets.kt @@ -98,16 +98,6 @@ public fun Sequence.distinct(): Sequence { return this.distinctBy { it } } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing only distinct elements from the given stream. - * The elements in the resulting stream are in the same order as they were in the source stream. - */ -public fun Stream.distinct(): Stream { - return this.distinctBy { it } -} - /** * Returns a list containing only distinct elements from the given collection according to the [keySelector]. * The elements in the resulting list are in the same order as they were in the source collection. @@ -266,16 +256,6 @@ public fun Sequence.distinctBy(keySelector: (T) -> K): Sequence { return DistinctSequence(this, keySelector) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing only distinct elements from the given stream according to the [keySelector]. - * The elements in the resulting stream are in the same order as they were in the source stream. - */ -public fun Stream.distinctBy(keySelector: (T) -> K): Stream { - return DistinctStream(this, keySelector) -} - /** * Returns a set containing all elements that are contained by both this set and the specified collection. */ @@ -556,17 +536,6 @@ public fun Sequence.toMutableSet(): MutableSet { return set } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a mutable set containing all distinct elements from the given stream. - */ -public fun Stream.toMutableSet(): MutableSet { - val set = LinkedHashSet() - for (item in this) set.add(item) - return set -} - /** * Returns a set containing all distinct elements from both collections. */ diff --git a/libraries/stdlib/src/generated/_Snapshots.kt b/libraries/stdlib/src/generated/_Snapshots.kt index 4770df2ff7a..e012804cf49 100644 --- a/libraries/stdlib/src/generated/_Snapshots.kt +++ b/libraries/stdlib/src/generated/_Snapshots.kt @@ -112,15 +112,6 @@ public fun Sequence.toArrayList(): ArrayList { return toCollection(ArrayList()) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns an [ArrayList] of all elements. - */ -public fun Stream.toArrayList(): ArrayList { - return toCollection(ArrayList()) -} - /** * Returns an [ArrayList] of all elements. */ @@ -238,18 +229,6 @@ public fun > Sequence.toCollection(collection: return collection } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements to the given [collection]. - */ -public fun > Stream.toCollection(collection: C): C { - for (item in this) { - collection.add(item) - } - return collection -} - /** * Appends all elements to the given [collection]. */ @@ -337,15 +316,6 @@ public fun Sequence.toHashSet(): HashSet { return toCollection(HashSet()) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a [HashSet] of all elements. - */ -public fun Stream.toHashSet(): HashSet { - return toCollection(HashSet()) -} - /** * Returns a [HashSet] of all elements. */ @@ -430,15 +400,6 @@ public fun Sequence.toLinkedList(): LinkedList { return toCollection(LinkedList()) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a [LinkedList] containing all elements. - */ -public fun Stream.toLinkedList(): LinkedList { - return toCollection(LinkedList()) -} - /** * Returns a [LinkedList] containing all elements. */ @@ -533,15 +494,6 @@ public fun Sequence.toList(): List { return this.toArrayList() } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a [List] containing all elements. - */ -public fun Stream.toList(): List { - return this.toArrayList() -} - /** * Returns a [List] containing all elements. */ @@ -691,20 +643,6 @@ public inline fun Sequence.toMap(selector: (T) -> K): Map { return result } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns Map containing the values from the given collection indexed by [selector]. - * If any two elements would have the same key returned by [selector] the last one gets added to the map. - */ -public inline fun Stream.toMap(selector: (T) -> K): Map { - val result = LinkedHashMap() - for (element in this) { - result.put(selector(element), element) - } - return result -} - /** * Returns Map containing the values from the given collection indexed by [selector]. * If any two elements would have the same key returned by [selector] the last one gets added to the map. @@ -860,20 +798,6 @@ public inline fun Sequence.toMap(selector: (T) -> K, transform: (T) return result } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection. - * If any two elements would have the same key returned by [selector] the last one gets added to the map. - */ -public inline fun Stream.toMap(selector: (T) -> K, transform: (T) -> V): Map { - val result = LinkedHashMap() - for (element in this) { - result.put(selector(element), transform(element)) - } - return result -} - /** * Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection. * If any two elements would have the same key returned by [selector] the last one gets added to the map. @@ -964,15 +888,6 @@ public fun Sequence.toSet(): Set { return toCollection(LinkedHashSet()) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a [Set] of all elements. - */ -public fun Stream.toSet(): Set { - return toCollection(LinkedHashSet()) -} - /** * Returns a [Set] of all elements. */ @@ -1057,15 +972,6 @@ public fun Sequence.toSortedSet(): SortedSet { return toCollection(TreeSet()) } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a [SortedSet] of all elements. - */ -public fun Stream.toSortedSet(): SortedSet { - return toCollection(TreeSet()) -} - /** * Returns a [SortedSet] of all elements. */ diff --git a/libraries/stdlib/src/generated/_SpecialJVM.kt b/libraries/stdlib/src/generated/_SpecialJVM.kt index 8c325de7f8c..b4502eb4aef 100644 --- a/libraries/stdlib/src/generated/_SpecialJVM.kt +++ b/libraries/stdlib/src/generated/_SpecialJVM.kt @@ -475,15 +475,6 @@ public inline fun Sequence<*>.filterIsInstance(): Sequence { return filter { it is R } as Sequence } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements that are instances of specified type parameter R. - */ -public inline fun Stream<*>.filterIsInstance(): Stream { - return filter { it is R } as Stream -} - /** * Returns a list containing all elements that are instances of specified class. */ @@ -505,15 +496,6 @@ public fun Sequence<*>.filterIsInstance(klass: Class): Sequence { return filter { klass.isInstance(it) } as Sequence } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Returns a stream containing all elements that are instances of specified class. - */ -public fun Stream<*>.filterIsInstance(klass: Class): Stream { - return filter { klass.isInstance(it) } as Stream -} - /** * Appends all elements that are instances of specified type parameter R to the given [destination]. */ @@ -538,16 +520,6 @@ public inline fun > Sequence<*>.filterIsI return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements that are instances of specified type parameter R to the given [destination]. - */ -public inline fun > Stream<*>.filterIsInstanceTo(destination: C): C { - for (element in this) if (element is R) destination.add(element) - return destination -} - /** * Appends all elements that are instances of specified class to the given [destination]. */ @@ -572,16 +544,6 @@ public fun , R> Sequence<*>.filterIsInstanceTo(desti return destination } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends all elements that are instances of specified class to the given [destination]. - */ -public fun , R> Stream<*>.filterIsInstanceTo(destination: C, klass: Class): C { - for (element in this) if (klass.isInstance(element)) destination.add(element as R) - return destination -} - /** * Sorts array or range in array inplace. */ diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index 6b059681ef5..81f939da5d2 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -230,28 +230,6 @@ public fun Sequence.joinTo(buffer: A, separator: String = return buffer } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied. - * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] - * elements will be appended, followed by the [truncated] string (which defaults to "..."). - */ -public fun Stream.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): A { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (transform != null) transform(element) else if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) - return buffer -} - /** * Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied. * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] @@ -351,14 +329,3 @@ public fun Sequence.joinToString(separator: String = ", ", prefix: String return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString() } - -deprecated("Migrate to using Sequence and respective functions") -/** - * Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied. - * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] - * elements will be appended, followed by the [truncated] string (which defaults to "..."). - */ -public fun Stream.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): String { - return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString() -} - diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index 0833c2a8718..81d4e2b0ffb 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -17,14 +17,6 @@ public fun MutableCollection.addAll(sequence: Sequence) { for (item in sequence) add(item) } -/** - * Adds all elements of the given [sequence] to this [MutableCollection]. - */ -deprecated("Use Sequence instead of Stream") -public fun MutableCollection.addAll(stream: Stream) { - for (item in stream) add(item) -} - /** * Adds all elements of the given [array] to this [MutableCollection]. */ @@ -49,14 +41,6 @@ public fun MutableCollection.removeAll(sequence: Sequence) { for (item in sequence) remove(item) } -/** - * Removes all elements of the given [stream] from this [MutableCollection]. - */ -deprecated("Use Sequence instead of Stream") -public fun MutableCollection.removeAll(stream: Stream) { - for (item in stream) remove(item) -} - /** * Removes all elements of the given [array] from this [MutableCollection]. */ diff --git a/libraries/stdlib/src/kotlin/collections/Operations.kt b/libraries/stdlib/src/kotlin/collections/Operations.kt index a361a1412f5..0a2b757248d 100644 --- a/libraries/stdlib/src/kotlin/collections/Operations.kt +++ b/libraries/stdlib/src/kotlin/collections/Operations.kt @@ -21,14 +21,6 @@ public fun Sequence>.flatten(): Sequence { return MultiSequence(this) } -/** - * Returns a sequence of all elements from all sequences in this sequence. - */ -deprecated("Use Sequence instead of Stream") -public fun Stream>.flatten(): Stream { - return FlatteningStream(this, { it }) -} - /** * Returns a single list of all elements from all arrays in the given array. */ diff --git a/libraries/stdlib/src/kotlin/collections/Sequence.kt b/libraries/stdlib/src/kotlin/collections/Sequence.kt index 9ca2c35c5ce..44369f52409 100644 --- a/libraries/stdlib/src/kotlin/collections/Sequence.kt +++ b/libraries/stdlib/src/kotlin/collections/Sequence.kt @@ -3,35 +3,17 @@ package kotlin import java.util.* import kotlin.support.AbstractIterator -deprecated("Use Sequence instead.") -public interface Stream { - /** - * Returns an iterator that returns the values from the sequence. - */ - public fun iterator(): Iterator -} - /** * A sequence that returns values through its iterator. The values are evaluated lazily, and the sequence * is potentially infinite. * * @param T the type of elements in the sequence. */ -public interface Sequence : Stream - -/** - * Converts a stream to a sequence. - */ -public fun Stream.toSequence(): Sequence = object : Sequence { - override fun iterator(): Iterator = this@toSequence.iterator() -} - -deprecated("Use sequenceOf() instead", ReplaceWith("sequenceOf(*elements)")) -public fun streamOf(vararg elements: T): Stream = elements.stream() - -deprecated("Use sequenceOf() instead", ReplaceWith("sequenceOf(progression)")) -public fun streamOf(progression: Progression): Stream = object : Stream { - override fun iterator(): Iterator = progression.iterator() +public interface Sequence { + /** + * Returns an iterator that returns the values from the sequence. + */ + public fun iterator(): Iterator } /** @@ -70,17 +52,10 @@ public fun sequenceOf(progression: Progression): Sequence = object : S */ public fun emptySequence(): Sequence = EmptySequence -deprecated("Remove in M13 with streams.") -private fun emptyStream(): Stream = EmptySequence - private object EmptySequence : Sequence { override fun iterator(): Iterator = EmptyIterator } -deprecated("Use FilteringSequence instead") -public class FilteringStream(stream: Stream, sendWhen: Boolean = true, predicate: (T) -> Boolean) -: Stream by FilteringSequence(stream.toSequence(), sendWhen, predicate) - /** * A sequence that returns the values from the underlying [sequence] that either match or do not match * the specified [predicate]. @@ -130,10 +105,6 @@ public class FilteringSequence(private val sequence: Sequence, } } -deprecated("Use TransformingSequence instead") -public class TransformingStream(stream: Stream, transformer: (T) -> R) -: Stream by TransformingSequence(stream.toSequence(), transformer) - /** * A sequence which returns the results of applying the given [transformer] function to the values * in the underlying [sequence]. @@ -154,10 +125,6 @@ constructor(private val sequence: Sequence, private val transformer: (T) -> R } } -deprecated("Use TransformingIndexedSequence instead") -public class TransformingIndexedStream(stream: Stream, transformer: (Int, T) -> R) -: Stream by TransformingIndexedSequence(stream.toSequence(), transformer) - /** * A sequence which returns the results of applying the given [transformer] function to the values * in the underlying [sequence], where the transformer function takes the index of the value in the underlying @@ -180,10 +147,6 @@ constructor(private val sequence: Sequence, private val transformer: (Int, T) } } -deprecated("Use IndexingSequence instead") -public class IndexingStream(stream: Stream) -: Stream> by IndexingSequence(stream.toSequence()) - /** * A sequence which combines values from the underlying [sequence] with their indices and returns them as * [IndexedValue] objects. @@ -205,10 +168,6 @@ constructor(private val sequence: Sequence) : Sequence> { } } -deprecated("Use MergingSequence instead") -public class MergingStream(stream1: Stream, stream2: Stream, transform: (T1, T2) -> V) -: Stream by MergingSequence(stream1.toSequence(), stream2.toSequence(), transform) - /** * A sequence which takes the values from two parallel underlying sequences, passes them to the given * [transform] function and returns the values returned by that function. The sequence stops returning @@ -234,10 +193,6 @@ deprecated("This class is an implementation detail and shall be made internal so } } -deprecated("Use FlatteningSequence instead") -public class FlatteningStream(stream: Stream, transformer: (T) -> Stream) -: Stream by FlatteningSequence(stream.toSequence(), { transformer(it).toSequence() }) - deprecated("This class is an implementation detail and shall be made internal soon. Use sequence.flatMap() instead.") public class FlatteningSequence deprecated("This class is an implementation detail and shall be made internal soon.", ReplaceWith("sequence.flatMap(transformer)")) @@ -279,10 +234,6 @@ deprecated("This class is an implementation detail and shall be made internal so } } -deprecated("Use MultiSequence instead") -public class Multistream(stream: Stream>) -: Stream by FlatteningSequence(stream.toSequence(), { it.toSequence() }) - deprecated("This class is an implementation detail and shall be made internal soon. Use sequence.flatten() instead.") public class MultiSequence deprecated("This class is an implementation detail and shall be made internal soon.", ReplaceWith("sequence.flatten()")) @@ -322,10 +273,6 @@ constructor(private val sequence: Sequence>) : Sequence { } } -deprecated("Use TakeSequence instead") -public class TakeStream(stream: Stream, count: Int) -: Stream by TakeSequence(stream.toSequence(), count) - /** * A sequence that returns at most [count] values from the underlying [sequence], and stops returning values * as soon as that count is reached. @@ -357,9 +304,6 @@ deprecated("This class is an implementation detail and shall be made internal so } } -deprecated("Use TakeWhileSequence instead") -public class TakeWhileStream(stream: Stream, predicate: (T) -> Boolean) : Stream by TakeWhileSequence(stream.toSequence(), predicate) - /** * A sequence that returns values from the underlying [sequence] while the [predicate] function returns * `true`, and stops returning values once the function returns `false` for the next element. @@ -408,10 +352,6 @@ deprecated("This class is an implementation detail and shall be made internal so } } -deprecated("Use DropSequence instead") -public class DropStream(stream: Stream, count: Int) -: Stream by DropSequence(stream.toSequence(), count) - /** * A sequence that skips the specified number of values from the underlying [sequence] and returns * all values after that. @@ -450,9 +390,6 @@ deprecated("This class is an implementation detail and shall be made internal so } } -deprecated("Use DropWhileSequence instead") -public class DropWhileStream(stream: Stream, predicate: (T) -> Boolean) : Stream by DropWhileSequence(stream.toSequence(), predicate) - /** * A sequence that skips the values from the underlying [sequence] while the given [predicate] returns `true` and returns * all values after that. @@ -502,9 +439,6 @@ deprecated("This class is an implementation detail and shall be made internal so } } -deprecated("Use DistinctSequence instead and remove with streams.") -private class DistinctStream(private val source: Stream, private val keySelector : (T) -> K) : Stream by DistinctSequence(source.toSequence(), keySelector) - private class DistinctSequence(private val source : Sequence, private val keySelector : (T) -> K) : Sequence { override fun iterator(): Iterator = DistinctIterator(source.iterator(), keySelector) } @@ -624,9 +558,6 @@ public fun sequence(nextFunction: () -> T?): Sequence { return GeneratorSequence(nextFunction, { nextFunction() }).constrainOnce() } -deprecated("Use sequence() instead", ReplaceWith("sequence(nextFunction)")) -public fun stream(nextFunction: () -> T?): Sequence = sequence(nextFunction) - /** * Returns a sequence which invokes the function to calculate the next value based on the previous one on each iteration * until the function returns `null`. The sequence starts with the specified [initialValue]. @@ -643,6 +574,3 @@ public /*inline*/ fun sequence(initialValue: T, nextFunction: (T) -> T */ public fun sequence(initialValueFunction: () -> T?, nextFunction: (T) -> T?): Sequence = GeneratorSequence(initialValueFunction, nextFunction) - -deprecated("Use sequence() instead", ReplaceWith("sequence(initialValue, nextFunction)")) -public /*inline*/ fun stream(initialValue: T, nextFunction: (T) -> T?): Sequence = sequence(initialValue, nextFunction) diff --git a/libraries/stdlib/src/kotlin/deprecated/DeprecatedIterators.kt b/libraries/stdlib/src/kotlin/deprecated/DeprecatedIterators.kt deleted file mode 100644 index 00d9bf02a4a..00000000000 --- a/libraries/stdlib/src/kotlin/deprecated/DeprecatedIterators.kt +++ /dev/null @@ -1,225 +0,0 @@ -package kotlin - -import kotlin.support.* -import java.util.Collections -import kotlin.test.assertTrue - -/** - * Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns *null* - */ -deprecated("Use sequence(...) function to make lazy sequence of values.") -public fun iterate(nextFunction: () -> T?) : Iterator { - return FunctionIterator(nextFunction) -} - -/** - * Returns an iterator which invokes the function to calculate the next value based on the previous one on each iteration - * until the function returns *null* - */ -deprecated("Use sequence(...) function to make lazy sequence of values.") -public /*inline*/ fun iterate(initialValue: T, nextFunction: (T) -> T?): Iterator = - iterate(nextFunction.toGenerator(initialValue)) - -/** - * Returns an iterator whose values are pairs composed of values produced by given pair of iterators - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.zip(iterator: Iterator): Iterator> = PairIterator(this, iterator) - -/** - * Returns an iterator shifted to right by the given number of elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.skip(n: Int): Iterator = SkippingIterator(this, n) - -deprecated("Use FilteringStream instead") -public class FilterIterator(private val iterator: Iterator, private val predicate: (T) -> Boolean) : - AbstractIterator() { - override protected fun computeNext(): Unit { - while (iterator.hasNext()) { - val next = iterator.next() - if ((predicate)(next)) { - setNext(next) - return - } - } - done() - } -} - -deprecated("Use FilteringStream instead") -public class FilterNotNullIterator(private val iterator: Iterator?) : AbstractIterator() { - override protected fun computeNext(): Unit { - if (iterator != null) { - while (iterator.hasNext()) { - val next = iterator.next() - if (next != null) { - setNext(next) - return - } - } - } - done() - } -} - -deprecated("Use TransformingStream instead") -public class MapIterator(private val iterator: Iterator, private val transform: (T) -> R) : - AbstractIterator() { - override protected fun computeNext(): Unit { - if (iterator.hasNext()) { - setNext((transform)(iterator.next())) - } else { - done() - } - } -} - -deprecated("Use FlatteningStream instead") -public class FlatMapIterator(private val iterator: Iterator, private val transform: (T) -> Iterator) : - AbstractIterator() { - private var transformed: Iterator = iterate { null } - - override protected fun computeNext(): Unit { - while (true) { - if (transformed.hasNext()) { - setNext(transformed.next()) - return - } - if (iterator.hasNext()) { - transformed = (transform)(iterator.next()) - } else { - done() - return - } - } - } -} - -deprecated("Use LimitedStream instead") -public class TakeWhileIterator(private val iterator: Iterator, private val predicate: (T) -> Boolean) : - AbstractIterator() { - override protected fun computeNext() : Unit { - if (iterator.hasNext()) { - val item = iterator.next() - if ((predicate)(item)) { - setNext(item) - return - } - } - done() - } -} - -/** An [[Iterator]] which invokes a function to calculate the next value in the iteration until the function returns *null* */ -deprecated("Use FunctionStream instead") -public class FunctionIterator(private val nextFunction: () -> T?) : AbstractIterator() { - - override protected fun computeNext(): Unit { - val next = (nextFunction)() - if (next == null) { - done() - } else { - setNext(next) - } - } -} - -/** An [[Iterator]] which iterates over a number of iterators in sequence */ -deprecated("Use Multistream instead") -public fun CompositeIterator(vararg iterators: Iterator): CompositeIterator = CompositeIterator(iterators.iterator()) - -deprecated("Use Multistream instead") -public class CompositeIterator(private val iterators: Iterator>) : AbstractIterator() { - - private var currentIter: Iterator? = null - - override protected fun computeNext(): Unit { - while (true) { - if (currentIter == null) { - if (iterators.hasNext()) { - currentIter = iterators.next() - } else { - done() - return - } - } - val iter = currentIter - if (iter != null) { - if (iter.hasNext()) { - setNext(iter.next()) - return - } else { - currentIter = null - } - } - } - } -} - -/** A singleton [[Iterator]] which invokes once over a value */ -deprecated("Use streams for lazy collection operations.") -public class SingleIterator(private val value: T) : AbstractIterator() { - private var first = true - - override protected fun computeNext(): Unit { - if (first) { - first = false - setNext(value) - } else { - done() - } - } -} - -deprecated("Use streams for lazy collection operations.") -public class IndexIterator(private val iterator: Iterator) : Iterator> { - private var index: Int = 0 - - override fun next(): Pair { - return Pair(index++, iterator.next()) - } - - override fun hasNext(): Boolean { - return iterator.hasNext() - } -} - -deprecated("Use ZippingStream instead.") -public class PairIterator( - private val iterator1: Iterator, private val iterator2: Iterator -): AbstractIterator>() { - protected override fun computeNext() { - if (iterator1.hasNext() && iterator2.hasNext()) { - setNext(Pair(iterator1.next(), iterator2.next())) - } - else { - done() - } - } -} - -deprecated("Use streams for lazy collection operations.") -public class SkippingIterator(private val iterator: Iterator, private val n: Int) : Iterator { - private var firstTime: Boolean = true - - private fun skip() { - for (i in 1..n) { - if (!iterator.hasNext()) break - iterator.next() - } - firstTime = false - } - - override fun next(): T { - assertTrue(!firstTime, "hasNext() must be invoked before advancing an iterator") - return iterator.next() - } - - override fun hasNext(): Boolean { - if (firstTime) { - skip() - } - return iterator.hasNext() - } -} diff --git a/libraries/stdlib/src/kotlin/deprecated/DeprecatedIteratorsJVM.kt b/libraries/stdlib/src/kotlin/deprecated/DeprecatedIteratorsJVM.kt deleted file mode 100644 index 6970325a430..00000000000 --- a/libraries/stdlib/src/kotlin/deprecated/DeprecatedIteratorsJVM.kt +++ /dev/null @@ -1,23 +0,0 @@ -package kotlin - -import kotlin.support.* - -/** Returns an iterator over elements that are instances of a given type *R* which is a subclass of *T* */ -deprecated("Use streams for lazy collection operations.") -public fun Iterator.filterIsInstance(klass: Class): Iterator = FilterIsIterator(this, klass) - -deprecated("Use streams for lazy collection operations.") -public class FilterIsIterator(private val iterator: Iterator, private val klass: Class) : - AbstractIterator() { - override protected fun computeNext(): Unit { - while (iterator.hasNext()) { - val next = iterator.next() - if (klass.isInstance(next)) { - setNext(next as R) - return - } - } - done() - } -} - diff --git a/libraries/stdlib/src/kotlin/deprecated/_Iterators.kt b/libraries/stdlib/src/kotlin/deprecated/_Iterators.kt deleted file mode 100644 index c8e755d79a1..00000000000 --- a/libraries/stdlib/src/kotlin/deprecated/_Iterators.kt +++ /dev/null @@ -1,492 +0,0 @@ -package kotlin - -import java.util.* -import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js - -/** - * Returns *true* if all elements match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.all(predicate: (T) -> Boolean) : Boolean { - for (element in this) if (!predicate(element)) return false - return true -} - -/** - * Returns *true* if any elements match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.any(predicate: (T) -> Boolean) : Boolean { - for (element in this) if (predicate(element)) return true - return false -} - -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) -} - -/** - * Returns the number of elements which match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.count(predicate: (T) -> Boolean) : Int { - var count = 0 - for (element in this) if (predicate(element)) count++ - return count -} - -/** - * Returns a list containing everything but the first *n* elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.drop(n: Int) : List { - return dropWhile(countTo(n)) -} - -/** - * Returns a list containing the everything but the first elements that satisfy the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.dropWhile(predicate: (T) -> Boolean) : List { - return dropWhileTo(ArrayList(), predicate) -} - -/** - * Returns a list containing the everything but the first elements that satisfy the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.dropWhileTo(result: L, predicate: (T) -> Boolean) : L { - var start = true - for (element in this) { - if (start && predicate(element)) { - // ignore - } else { - start = false - result.add(element) - } - } - return result -} - -/** - * Returns an iterator over elements which match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.filter(predicate: (T) -> Boolean) : Iterator { - return FilterIterator(this, predicate) -} - -/** - * Returns an iterator over elements which don't match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.filterNot(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) predicate: (T) -> Boolean) : Iterator { - return filter {!predicate(it)} -} - -/** - * Returns an iterator over non-*null* elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.filterNotNull() : Iterator { - return FilterNotNullIterator(this) -} - -/** - * Filters all non-*null* elements into the given list - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun > Iterator.filterNotNullTo(result: C) : C { - for (element in this) if (element != null) result.add(element) - return result -} - -/** - * Returns a list containing all elements which do not match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.filterNotTo(result: C, predicate: (T) -> Boolean) : C { - for (element in this) if (!predicate(element)) result.add(element) - return result -} - -/** - * Filters all elements which match the given predicate into the given list - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.filterTo(result: C, predicate: (T) -> Boolean) : C { - for (element in this) if (predicate(element)) result.add(element) - return result -} - -/** - * Returns the first element which matches the given *predicate* or *null* if none matched - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.find(predicate: (T) -> Boolean) : T? { - for (element in this) if (predicate(element)) return element - return null -} - -/** - * Returns an iterator over the concatenated results of transforming each element to one or more values - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.flatMap(transform: (T) -> Iterator) : Iterator { - return FlatMapIterator(this, transform) -} - -/** - * Returns the result of transforming each element to one or more values which are concatenated together into a single collection - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.flatMapTo(result: C, transform: (T) -> Iterable) : C { - for (element in this) { - val list = transform(element) - for (r in list) result.add(r) - } - return result -} - -/** - * Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.fold(initial: R, operation: (R, T) -> R) : R { - var answer = initial - for (element in this) answer = operation(answer, element) - return answer -} - -/** - * Performs the given *operation* on each element - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.forEach(operation: (T) -> Unit) : Unit { - for (element in this) operation(element) -} - -/** - * Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.groupBy(toKey: (T) -> K) : Map> { - return groupByTo(HashMap>(), toKey) -} - -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.groupByTo(result: MutableMap>, toKey: (T) -> K) : Map> { - for (element in this) { - val key = toKey(element) - val list = result.getOrPut(key) { ArrayList() } - list.add(element) - } - return result -} - -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() -} - -// ------------------------- - -/** - * Returns an iterator obtained by applying *transform*, a function transforming an object of type *T* into an object of type *R* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.map(transform : (T) -> R) : Iterator { - return MapIterator(this, transform) -} - -/** - * Transforms each element of this collection with the given *transform* function and - * adds each return value to the given *results* collection - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.mapTo(result: C, transform : (T) -> R) : C { - for (item in this) - result.add(transform(item)) - return result -} - -/** - * Returns the largest element or null if there are no elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun > Iterator.max() : T? { - if (!hasNext()) return null - - var max = next() - while (hasNext()) { - val e = next() - if (max < e) max = e - } - return max -} - -/** - * Returns the first element yielding the largest value of the given function or null if there are no elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun , T: Any> Iterator.maxBy(f: (T) -> R) : T? { - if (!hasNext()) return null - - var maxElem = next() - var maxValue = f(maxElem) - while (hasNext()) { - val e = next() - val v = f(e) - if (maxValue < v) { - maxElem = e - maxValue = v - } - } - return maxElem -} - -/** - * Returns the smallest element or null if there are no elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun > Iterator.min() : T? { - if (!hasNext()) return null - - var min = next() - while (hasNext()) { - val e = next() - if (min > e) min = e - } - return min -} - -/** - * Returns the first element yielding the smallest value of the given function or null if there are no elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun , T: Any> Iterator.minBy(f: (T) -> R) : T? { - if (!hasNext()) return null - - var minElem = next() - var minValue = f(minElem) - while (hasNext()) { - val e = next() - val v = f(e) - if (minValue > v) { - minElem = e - minValue = v - } - } - return minElem -} - -/** - * Partitions this collection into a pair of collections - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.partition(predicate: (T) -> Boolean) : Pair, List> { - val first = ArrayList() - val second = ArrayList() - for (element in this) { - if (predicate(element)) { - first.add(element) - } else { - second.add(element) - } - } - return Pair(first, second) -} - -/** - * Creates an [[Iterator]] which iterates over this iterator then the following collection - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.plus(collection: Iterable) : Iterator { - return plus(collection.iterator()) -} - -/** - * Creates an [[Iterator]] which iterates over this iterator then the given element at the end - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.plus(element: T) : Iterator { - return CompositeIterator(this, SingleIterator(element)) -} - -/** - * Creates an [[Iterator]] which iterates over this iterator then the following iterator - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.plus(iterator: Iterator) : Iterator { - return CompositeIterator(this, iterator) -} - -/** - * Applies binary operation to all elements of iterable, going from left to right. - * Similar to fold function, but uses the first element as initial value - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun Iterator.reduce(operation: (T, T) -> T) : T { - val iterator = this.iterator() - if (!iterator.hasNext()) { - throw UnsupportedOperationException("Empty iterable can't be reduced") - } - - var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway - while (iterator.hasNext()) { - result = operation(result, iterator.next()) - } - - return result -} - -/** - * Returns a original Iterable containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.requireNoNulls() : Iterator { - return map{ - if (it == null) throw IllegalArgumentException("null element in iterator $this") else it - } -} - -/** - * Reverses the order the elements into a list - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.reverse() : List { - val list = toCollection(ArrayList()) - Collections.reverse(list) - return list -} - -/** - * Copies all elements into a [[List]] and sorts it by value of compare_function(element) - * E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) f: (T) -> R) : List { - val sortedList = toCollection(ArrayList()) - val sortBy: Comparator = comparator {x: T, y: T -> - val xr = f(x) - val yr = f(y) - xr.compareTo(yr) - } - java.util.Collections.sort(sortedList, sortBy) - return sortedList -} - -/** - * Returns an iterator restricted to the first *n* elements - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.take(n: Int) : Iterator { - var count = n - return takeWhile{ --count >= 0 } -} - -/** - * Returns an iterator restricted to the first elements that match the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.takeWhile(predicate: (T) -> Boolean) : Iterator { - return TakeWhileIterator(this, predicate) -} - -/** - * Returns a list containing the first elements that satisfy the given *predicate* - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public inline fun > Iterator.takeWhileTo(result: C, predicate: (T) -> Boolean) : C { - for (element in this) if (predicate(element)) result.add(element) else break - return result -} - -/** - * Copies all elements into the given collection - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun > Iterator.toCollection(result: C) : C { - for (element in this) result.add(element) - return result -} - -/** - * Copies all elements into a [[LinkedList]] - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.toLinkedList() : LinkedList { - return toCollection(LinkedList()) -} - -/** - * Copies all elements into a [[List]] - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.toList() : List { - return toCollection(ArrayList()) -} - -/** - * Copies all elements into a [[ArrayList]] - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.toArrayList() : ArrayList { - return toCollection(ArrayList()) -} - -/** - * Copies all elements into a [[Set]] - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.toSet() : Set { - return toCollection(LinkedHashSet()) -} - -/** - * Copies all elements into a [[HashSet]] - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.toHashSet() : HashSet { - return toCollection(HashSet()) -} - -/** - * Copies all elements into a [[SortedSet]] - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.toSortedSet() : SortedSet { - return toCollection(TreeSet()) -} - -/** - * Returns an iterator of Pairs(index, data) - */ -deprecated("Replace Iterator with Sequence by using sequence() function instead of iterator()") -public fun Iterator.withIndices() : Iterator> { - return IndexIterator(iterator()) -} - diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 27f53ceab6f..17e5db2b61a 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -269,11 +269,6 @@ public fun Sequence.join(separator: String = ", ", prefix: String = "", return joinToString(separator, prefix, postfix, limit, truncated) } -deprecated("Migrate to using Sequence and respective functions") -public fun Stream.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - return joinToString(separator, prefix, postfix, limit, truncated) -} - /** * Returns a substring before the first occurrence of [delimiter]. * If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string. diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt index e20e015bcba..d271af9f2a5 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt @@ -148,24 +148,6 @@ 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() - if (deprecate[f] == null) // (deprecates[f] == null && deprecate.isEmpty()) - builder.appendln("deprecated(\"Migrate to using Sequence 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 = returns[f] ?: throw RuntimeException("No return type specified for $signature") val isAsteriskOrT = if (receiverAsterisk) "*" else "T" diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index 1a73f95f9d2..915fd8e0775 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -86,7 +86,7 @@ fun generators(): List { returns("Sequence") body { """ - return sequenceOf(this, collection.sequence()).flatten() + return sequenceOf(this, collection.asSequence()).flatten() """ } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt index 3d26075baf4..8f25dbb53cb 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Sequence.kt @@ -5,26 +5,6 @@ import templates.Family.* fun sequences(): List { val templates = arrayListOf() - templates add f("stream()") { - include(Maps) - exclude(Sequences) - deprecate { "Use asSequence() instead" } - doc { "Returns a sequence from the given collection" } - deprecateReplacement { "asSequence()" } - returns("Stream") - body { - """ - val sequence = asSequence() - return object : Stream { - override fun iterator(): Iterator { - return sequence.iterator() - } - } - """ - } - - } - templates add f("sequence()") { include(Maps) exclude(Sequences)