StdLib cleanup: drop deprecated iterators and streams.

This commit is contained in:
Ilya Gorbunov
2015-06-26 00:09:38 +03:00
parent 6d4e48ab9a
commit 4660b07687
23 changed files with 7 additions and 2320 deletions
@@ -106,16 +106,6 @@ public inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean {
return true
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns `true` if all elements match the given [predicate].
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.any(): Boolean {
return false
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns `true` if collection has at least one element.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.any(predicate: (T) -> Boolean): Boolean {
return false
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns `true` if at least one element matches the given [predicate].
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.count(): Int {
return count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the number of elements in this collection.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.count(predicate: (T) -> Boolean): Int {
return count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the number of elements matching the given [predicate].
*/
public inline fun <T> Stream<T>.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 <T, R> Sequence<T>.fold(initial: R, operation: (R, T) -> R): R
return accumulator
}
deprecated("Migrate to using Sequence<T> 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 <T, R> Stream<T>.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 <T> Sequence<T>.forEach(operation: (T) -> Unit): Unit {
for (element in this) operation(element)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Performs the given [operation] on each element.
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.forEachIndexed(operation: (Int, T) -> Unit): U
for (item in this) operation(index++, item)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Performs the given [operation] on each element, providing sequential index with the element.
*/
public inline fun <T> Stream<T>.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 <T : Comparable<T>> Sequence<T>.max(): T? {
return max
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the largest element or `null` if there are no elements.
*/
public fun <T : Comparable<T>> Stream<T>.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 <R : Comparable<R>, T : Any> Sequence<T>.maxBy(f: (T) -> R): T
return maxElem
}
deprecated("Migrate to using Sequence<T> 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 <R : Comparable<R>, T : Any> Stream<T>.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 <T : Comparable<T>> Sequence<T>.min(): T? {
return min
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the smallest element or `null` if there are no elements.
*/
public fun <T : Comparable<T>> Stream<T>.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 <R : Comparable<R>, T : Any> Sequence<T>.minBy(f: (T) -> R): T
return minElem
}
deprecated("Migrate to using Sequence<T> 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 <R : Comparable<R>, T : Any> Stream<T>.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 <T> Sequence<T>.none(): Boolean {
return true
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns `true` if collection has no elements.
*/
public fun <T> Stream<T>.none(): Boolean {
for (element in this) return false
return true
}
/**
* Returns `true` if collection has no elements.
*/
@@ -2102,16 +1936,6 @@ public inline fun <T> Sequence<T>.none(predicate: (T) -> Boolean): Boolean {
return true
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns `true` if no elements match the given [predicate].
*/
public inline fun <T> Stream<T>.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 <S, T: S> Sequence<T>.reduce(operation: (S, T) -> S): S {
return accumulator
}
deprecated("Migrate to using Sequence<T> 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 <S, T: S> Stream<T>.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 <T> Sequence<T>.sumBy(transform: (T) -> Int): Int {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.sumByDouble(transform: (T) -> Double): Double
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
*/
public inline fun <T> Stream<T>.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.
*/
-331
View File
@@ -441,17 +441,6 @@ public fun <T> Sequence<T>.contains(element: T): Boolean {
return indexOf(element) >= 0
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns `true` if [element] is found in the collection.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.elementAt(index: Int): T {
return elementAtOrElse(index) { throw IndexOutOfBoundsException("Sequence doesn't contain element at index $index.") }
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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 <T> Sequence<T>.elementAtOrElse(index: Int, defaultValue: (Int
return defaultValue(index)
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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 <T> Sequence<T>.elementAtOrNull(index: Int): T? {
return null
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.first(): T {
}
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns first element.
* @throws [NoSuchElementException] if the collection is empty.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.first(predicate: (T) -> Boolean): T {
throw NoSuchElementException("No element matching predicate was found.")
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.firstOrNull(): T? {
}
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the first element, or `null` if the collection is empty.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.firstOrNull(predicate: (T) -> Boolean): T? {
return null
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.indexOf(element: T): Int {
return -1
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.indexOfFirst(predicate: (T) -> Boolean): Int {
return -1
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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 <T> Sequence<T>.indexOfLast(predicate: (T) -> Boolean): Int {
return lastIndex
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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 <T> Sequence<T>.last(): T {
return last
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the last element.
* @throws [NoSuchElementException] if the collection is empty.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.last(predicate: (T) -> Boolean): T {
return last as T
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the last element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.lastIndexOf(element: T): Int {
return lastIndex
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.lastOrNull(): T? {
return last
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the last element, or `null` if the collection is empty.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.lastOrNull(predicate: (T) -> Boolean): T? {
return last
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
public inline fun <T> Stream<T>.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 <T> Sequence<T>.single(): T {
}
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the single element, or throws an exception if the collection is empty or has more than one element.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.single(predicate: (T) -> Boolean): T {
return single as T
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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 <T> Sequence<T>.singleOrNull(): T? {
}
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns single element, or `null` if the collection is empty or has more than one element.
*/
public fun <T> Stream<T>.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 <T> Sequence<T>.singleOrNull(predicate: (T) -> Boolean): T? {
return single
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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.
*/
@@ -191,16 +191,6 @@ public fun <T> Sequence<T>.drop(n: Int): Sequence<T> {
return if (n == 0) this else DropSequence(this, n)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements except first [n] elements.
*/
public fun <T> Stream<T>.drop(n: Int): Stream<T> {
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 <T> Sequence<T>.dropWhile(predicate: (T) -> Boolean): Sequence<T> {
return DropWhileSequence(this, predicate)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements except first elements that satisfy the given [predicate].
*/
public fun <T> Stream<T>.dropWhile(predicate: (T) -> Boolean): Stream<T> {
return DropWhileStream(this, predicate)
}
/**
* Returns a string containing all characters except first characters that satisfy the given [predicate].
*/
@@ -683,15 +664,6 @@ public fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T> {
return FilteringSequence(this, true, predicate)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements matching the given [predicate].
*/
public fun <T> Stream<T>.filter(predicate: (T) -> Boolean): Stream<T> {
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 <T> Sequence<T>.filterNot(predicate: (T) -> Boolean): Sequence<T> {
return FilteringSequence(this, false, predicate)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements not matching the given [predicate].
*/
public fun <T> Stream<T>.filterNot(predicate: (T) -> Boolean): Stream<T> {
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 <T : Any> Sequence<T?>.filterNotNull(): Sequence<T> {
return filterNot { it == null } as Sequence<T>
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements that are not `null`.
*/
public fun <T : Any> Stream<T?>.filterNotNull(): Stream<T> {
return filterNot { it == null } as Stream<T>
}
/**
* Appends all elements that are not `null` to the given [destination].
*/
@@ -846,16 +800,6 @@ public fun <C : MutableCollection<in T>, T : Any> Sequence<T?>.filterNotNullTo(d
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends all elements that are not `null` to the given [destination].
*/
public fun <C : MutableCollection<in T>, T : Any> Stream<T?>.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 <T, C : MutableCollection<in T>> Sequence<T>.filterNotTo(desti
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*/
public inline fun <T, C : MutableCollection<in T>> Stream<T>.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 <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destinat
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends all elements matching the given [predicate] into the given [destination].
*/
public inline fun <T, C : MutableCollection<in T>> Stream<T>.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 <T> Sequence<T>.take(n: Int): Sequence<T> {
return if (n == 0) emptySequence() else TakeSequence(this, n)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing first [n] elements.
*/
public fun <T> Stream<T>.take(n: Int): Stream<T> {
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 <T> Sequence<T>.takeWhile(predicate: (T) -> Boolean): Sequence<T> {
return TakeWhileSequence(this, predicate)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing first elements satisfying the given [predicate].
*/
public fun <T> Stream<T>.takeWhile(predicate: (T) -> Boolean): Stream<T> {
return TakeWhileStream(this, predicate)
}
/**
* Returns a string containing the first characters that satisfy the given [predicate].
*/
+1 -67
View File
@@ -381,15 +381,6 @@ public fun <T, R, V> Sequence<T>.merge(sequence: Sequence<R>, transform: (T, R)
return MergingSequence(this, sequence, transform)
}
deprecated("Migrate to using Sequence<T> 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 <T, R, V> Stream<T>.merge(stream: Stream<R>, transform: (T, R) -> V): Stream<V> {
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 <T> Sequence<T>.partition(predicate: (T) -> Boolean): Pair<Lis
return Pair(first, second)
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.partition(predicate: (T) -> Boolean): Pair<List<T>, List<T>> {
val first = ArrayList<T>()
val second = ArrayList<T>()
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 <T> Iterable<T>.plus(collection: Iterable<T>): List<T> {
* Returns a sequence containing all elements of original sequence and then all elements of the given [collection].
*/
public fun <T> Sequence<T>.plus(collection: Iterable<T>): Sequence<T> {
return sequenceOf(this, collection.sequence()).flatten()
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements of original stream and then all elements of the given [collection].
*/
public fun <T> Stream<T>.plus(collection: Iterable<T>): Stream<T> {
return streamOf(this, collection.stream()).flatten()
return sequenceOf(this, collection.asSequence()).flatten()
}
/**
@@ -949,15 +911,6 @@ public fun <T> Sequence<T>.plus(element: T): Sequence<T> {
return sequenceOf(this, sequenceOf(element)).flatten()
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements of original stream and then the given [element].
*/
public fun <T> Stream<T>.plus(element: T): Stream<T> {
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 <T> Sequence<T>.plus(sequence: Sequence<T>): Sequence<T> {
return sequenceOf(this, sequence).flatten()
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements of original stream and then all elements of the given [stream].
*/
public fun <T> Stream<T>.plus(stream: Stream<T>): Stream<T> {
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 <T, R> Sequence<T>.zip(sequence: Sequence<R>): Sequence<Pair<T, R>> {
return MergingSequence(this, sequence) { t1, t2 -> t1 to t2 }
}
deprecated("Migrate to using Sequence<T> 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 <T, R> Stream<T>.zip(stream: Stream<R>): Stream<Pair<T, R>> {
return MergingStream(this, stream) { t1, t2 -> t1 to t2 }
}
@@ -53,12 +53,3 @@ public fun <T : Any> Sequence<T?>.requireNoNulls(): Sequence<T> {
return map { it ?: throw IllegalArgumentException("null element found in $this.") }
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements.
*/
public fun <T : Any> Stream<T?>.requireNoNulls(): Stream<T> {
return map { it ?: throw IllegalArgumentException("null element found in $this.") }
}
-131
View File
@@ -101,15 +101,6 @@ public fun <T, R> Sequence<T>.flatMap(transform: (T) -> Sequence<R>): Sequence<R
return FlatteningSequence(this, transform)
}
deprecated("Migrate to using Sequence<T> 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 <T, R> Stream<T>.flatMap(transform: (T) -> Stream<R>): Stream<R> {
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 <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(dest
return destination
}
deprecated("Migrate to using Sequence<T> 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 <T, R, C : MutableCollection<in R>> Stream<T>.flatMapTo(destination: C, transform: (T) -> Stream<R>): 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 <T, K> Sequence<T>.groupBy(toKey: (T) -> K): Map<K, List<T>> {
return groupByTo(LinkedHashMap<K, MutableList<T>>(), toKey)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a map of the elements in original collection grouped by the result of given [toKey] function.
*/
public inline fun <T, K> Stream<T>.groupBy(toKey: (T) -> K): Map<K, List<T>> {
return groupByTo(LinkedHashMap<K, MutableList<T>>(), 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 <T, K> Sequence<T>.groupByTo(map: MutableMap<K, MutableList<T>
return map
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends elements from original collection grouped by the result of given [toKey] function to the given [map].
*/
public inline fun <T, K> Stream<T>.groupByTo(map: MutableMap<K, MutableList<T>>, toKey: (T) -> K): Map<K, MutableList<T>> {
for (element in this) {
val key = toKey(element)
val list = map.getOrPut(key) { ArrayList<T>() }
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 <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R> {
return TransformingSequence(this, transform)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing the results of applying the given [transform] function to each element of the original stream.
*/
public fun <T, R> Stream<T>.map(transform: (T) -> R): Stream<R> {
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 <T, R> Sequence<T>.mapIndexed(transform: (Int, T) -> R): Sequence<R>
return TransformingIndexedSequence(this, transform)
}
deprecated("Migrate to using Sequence<T> 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 <T, R> Stream<T>.mapIndexed(transform: (Int, T) -> R): Stream<R> {
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 <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(d
return destination
}
deprecated("Migrate to using Sequence<T> 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 <T, R, C : MutableCollection<in R>> Stream<T>.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 <T : Any, R> Sequence<T?>.mapNotNull(transform: (T) -> R): Sequence<R
return TransformingSequence(FilteringSequence(this, false, { it == null }) as Sequence<T>, transform)
}
deprecated("Migrate to using Sequence<T> 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 <T : Any, R> Stream<T?>.mapNotNull(transform: (T) -> R): Stream<R> {
return TransformingStream(FilteringStream(this, false, { it == null }) as Stream<T>, 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 <T : Any, R, C : MutableCollection<in R>> Sequence<T?>.mapNotN
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends transformed non-null elements of original collection using the given [transform] function
* to the given [destination].
*/
public inline fun <T : Any, R, C : MutableCollection<in R>> Stream<T?>.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 <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destinat
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends transformed elements of the original collection using the given [transform] function
* to the given [destination].
*/
public inline fun <T, R, C : MutableCollection<in R>> Stream<T>.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 <T> Sequence<T>.withIndex(): Sequence<IndexedValue<T>> {
return IndexingSequence(this)
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream of [IndexedValue] for each element of the original stream.
*/
public fun <T> Stream<T>.withIndex(): Stream<IndexedValue<T>> {
return IndexingStream(this)
}
/**
* Returns a lazy [Iterable] of [IndexedValue] for each element of the original collection.
*/
@@ -1284,16 +1163,6 @@ public fun <T> Sequence<T>.withIndices(): Sequence<Pair<Int, T>> {
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 <T> Stream<T>.withIndices(): Stream<Pair<Int, T>> {
var index = 0
return TransformingStream(this, { index++ to it })
}
/**
* Returns a list containing pairs of each element of the original collection and their index.
*/
-192
View File
@@ -40,23 +40,6 @@ public fun Sequence<Int>.average(): Double {
return if (count == 0) 0.0 else sum / count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an average value of elements in the collection.
*/
platformName("averageOfInt")
public fun Stream<Int>.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<Long>.average(): Double {
return if (count == 0) 0.0 else sum / count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an average value of elements in the collection.
*/
platformName("averageOfLong")
public fun Stream<Long>.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<Byte>.average(): Double {
return if (count == 0) 0.0 else sum / count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an average value of elements in the collection.
*/
platformName("averageOfByte")
public fun Stream<Byte>.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<Short>.average(): Double {
return if (count == 0) 0.0 else sum / count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an average value of elements in the collection.
*/
platformName("averageOfShort")
public fun Stream<Short>.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<Double>.average(): Double {
return if (count == 0) 0.0 else sum / count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an average value of elements in the collection.
*/
platformName("averageOfDouble")
public fun Stream<Double>.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<Float>.average(): Double {
return if (count == 0) 0.0 else sum / count
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an average value of elements in the collection.
*/
platformName("averageOfFloat")
public fun Stream<Float>.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<Int>.sum(): Int {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfInt")
public fun Stream<Int>.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<Long>.sum(): Long {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfLong")
public fun Stream<Long>.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<Byte>.sum(): Int {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfByte")
public fun Stream<Byte>.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<Short>.sum(): Int {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfShort")
public fun Stream<Short>.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<Double>.sum(): Double {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfDouble")
public fun Stream<Double>.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<Float>.sum(): Float {
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfFloat")
public fun Stream<Float>.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.
*/
@@ -292,17 +292,6 @@ public fun <T : Comparable<T>> Sequence<T>.toSortedList(): List<T> {
return sortedList
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a sorted list of all elements.
*/
public fun <T : Comparable<T>> Stream<T>.toSortedList(): List<T> {
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 <T, V : Comparable<V>> Sequence<T>.toSortedListBy(order: (T) -> V): L
return sortedList
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a sorted list of all elements, ordered by results of specified [order] function.
*/
public fun <T, V : Comparable<V>> Stream<T>.toSortedListBy(order: (T) -> V): List<T> {
val sortedList = toArrayList()
val sortBy: Comparator<T> = compareBy(order)
java.util.Collections.sort(sortedList, sortBy)
return sortedList
}
@@ -138,15 +138,6 @@ public fun <T> Sequence<T>.asSequence(): Sequence<T> {
return this
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream from the given collection.
*/
public fun <T> Stream<T>.asStream(): Stream<T> {
return this
}
/**
* Returns a sequence from the given collection.
*/
@@ -254,15 +245,6 @@ public fun <T> Sequence<T>.sequence(): Sequence<T> {
return this
}
/**
* Returns a stream from the given collection
*/
deprecated("Use asStream() instead", ReplaceWith("asStream()"))
public fun <T> Stream<T>.stream(): Stream<T> {
return this
}
/**
* Returns a sequence from the given collection
*/
@@ -271,159 +253,3 @@ public fun String.sequence(): Sequence<Char> {
return asSequence()
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun <T> Array<out T>.stream(): Stream<T> {
val sequence = asSequence()
return object : Stream<T> {
override fun iterator(): Iterator<T> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun BooleanArray.stream(): Stream<Boolean> {
val sequence = asSequence()
return object : Stream<Boolean> {
override fun iterator(): Iterator<Boolean> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun ByteArray.stream(): Stream<Byte> {
val sequence = asSequence()
return object : Stream<Byte> {
override fun iterator(): Iterator<Byte> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun CharArray.stream(): Stream<Char> {
val sequence = asSequence()
return object : Stream<Char> {
override fun iterator(): Iterator<Char> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun DoubleArray.stream(): Stream<Double> {
val sequence = asSequence()
return object : Stream<Double> {
override fun iterator(): Iterator<Double> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun FloatArray.stream(): Stream<Float> {
val sequence = asSequence()
return object : Stream<Float> {
override fun iterator(): Iterator<Float> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun IntArray.stream(): Stream<Int> {
val sequence = asSequence()
return object : Stream<Int> {
override fun iterator(): Iterator<Int> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun LongArray.stream(): Stream<Long> {
val sequence = asSequence()
return object : Stream<Long> {
override fun iterator(): Iterator<Long> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun ShortArray.stream(): Stream<Short> {
val sequence = asSequence()
return object : Stream<Short> {
override fun iterator(): Iterator<Short> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun <T> Iterable<T>.stream(): Stream<T> {
val sequence = asSequence()
return object : Stream<T> {
override fun iterator(): Iterator<T> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun <K, V> Map<K, V>.stream(): Stream<Map.Entry<K, V>> {
val sequence = asSequence()
return object : Stream<Map.Entry<K, V>> {
override fun iterator(): Iterator<Map.Entry<K, V>> {
return sequence.iterator()
}
}
}
/**
* Returns a sequence from the given collection
*/
deprecated("Use asSequence() instead", ReplaceWith("asSequence()"))
public fun String.stream(): Stream<Char> {
val sequence = asSequence()
return object : Stream<Char> {
override fun iterator(): Iterator<Char> {
return sequence.iterator()
}
}
}
-31
View File
@@ -98,16 +98,6 @@ public fun <T> Sequence<T>.distinct(): Sequence<T> {
return this.distinctBy { it }
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.distinct(): Stream<T> {
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 <T, K> Sequence<T>.distinctBy(keySelector: (T) -> K): Sequence<T> {
return DistinctSequence(this, keySelector)
}
deprecated("Migrate to using Sequence<T> 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 <T, K> Stream<T>.distinctBy(keySelector: (T) -> K): Stream<T> {
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 <T> Sequence<T>.toMutableSet(): MutableSet<T> {
return set
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a mutable set containing all distinct elements from the given stream.
*/
public fun <T> Stream<T>.toMutableSet(): MutableSet<T> {
val set = LinkedHashSet<T>()
for (item in this) set.add(item)
return set
}
/**
* Returns a set containing all distinct elements from both collections.
*/
@@ -112,15 +112,6 @@ public fun <T> Sequence<T>.toArrayList(): ArrayList<T> {
return toCollection(ArrayList<T>())
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns an [ArrayList] of all elements.
*/
public fun <T> Stream<T>.toArrayList(): ArrayList<T> {
return toCollection(ArrayList<T>())
}
/**
* Returns an [ArrayList] of all elements.
*/
@@ -238,18 +229,6 @@ public fun <T, C : MutableCollection<in T>> Sequence<T>.toCollection(collection:
return collection
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends all elements to the given [collection].
*/
public fun <T, C : MutableCollection<in T>> Stream<T>.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 <T> Sequence<T>.toHashSet(): HashSet<T> {
return toCollection(HashSet<T>())
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a [HashSet] of all elements.
*/
public fun <T> Stream<T>.toHashSet(): HashSet<T> {
return toCollection(HashSet<T>())
}
/**
* Returns a [HashSet] of all elements.
*/
@@ -430,15 +400,6 @@ public fun <T> Sequence<T>.toLinkedList(): LinkedList<T> {
return toCollection(LinkedList<T>())
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a [LinkedList] containing all elements.
*/
public fun <T> Stream<T>.toLinkedList(): LinkedList<T> {
return toCollection(LinkedList<T>())
}
/**
* Returns a [LinkedList] containing all elements.
*/
@@ -533,15 +494,6 @@ public fun <T> Sequence<T>.toList(): List<T> {
return this.toArrayList()
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a [List] containing all elements.
*/
public fun <T> Stream<T>.toList(): List<T> {
return this.toArrayList()
}
/**
* Returns a [List] containing all elements.
*/
@@ -691,20 +643,6 @@ public inline fun <T, K> Sequence<T>.toMap(selector: (T) -> K): Map<K, T> {
return result
}
deprecated("Migrate to using Sequence<T> 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 <T, K> Stream<T>.toMap(selector: (T) -> K): Map<K, T> {
val result = LinkedHashMap<K, T>()
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 <T, K, V> Sequence<T>.toMap(selector: (T) -> K, transform: (T)
return result
}
deprecated("Migrate to using Sequence<T> 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 <T, K, V> Stream<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
val result = LinkedHashMap<K, V>()
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 <T> Sequence<T>.toSet(): Set<T> {
return toCollection(LinkedHashSet<T>())
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a [Set] of all elements.
*/
public fun <T> Stream<T>.toSet(): Set<T> {
return toCollection(LinkedHashSet<T>())
}
/**
* Returns a [Set] of all elements.
*/
@@ -1057,15 +972,6 @@ public fun <T> Sequence<T>.toSortedSet(): SortedSet<T> {
return toCollection(TreeSet<T>())
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a [SortedSet] of all elements.
*/
public fun <T> Stream<T>.toSortedSet(): SortedSet<T> {
return toCollection(TreeSet<T>())
}
/**
* Returns a [SortedSet] of all elements.
*/
@@ -475,15 +475,6 @@ public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<R> {
return filter { it is R } as Sequence<R>
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements that are instances of specified type parameter R.
*/
public inline fun <reified R> Stream<*>.filterIsInstance(): Stream<R> {
return filter { it is R } as Stream<R>
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
@@ -505,15 +496,6 @@ public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
return filter { klass.isInstance(it) } as Sequence<R>
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns a stream containing all elements that are instances of specified class.
*/
public fun <R> Stream<*>.filterIsInstance(klass: Class<R>): Stream<R> {
return filter { klass.isInstance(it) } as Stream<R>
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
@@ -538,16 +520,6 @@ public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsI
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
public inline fun <reified R, C : MutableCollection<in R>> 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 <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(desti
return destination
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
public fun <C : MutableCollection<in R>, R> Stream<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
/**
* Sorts array or range in array inplace.
*/
@@ -230,28 +230,6 @@ public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: String =
return buffer
}
deprecated("Migrate to using Sequence<T> 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 <T, A : Appendable> Stream<T>.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 <T> Sequence<T>.joinToString(separator: String = ", ", prefix: String
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
}
deprecated("Migrate to using Sequence<T> 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 <T> Stream<T>.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()
}