StdLib cleanup: drop deprecated iterators and streams.
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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].
|
||||
*/
|
||||
|
||||
@@ -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.") }
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,6 @@ public fun <T> MutableCollection<in T>.addAll(sequence: Sequence<T>) {
|
||||
for (item in sequence) add(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [sequence] to this [MutableCollection].
|
||||
*/
|
||||
deprecated("Use Sequence<T> instead of Stream<T>")
|
||||
public fun <T> MutableCollection<in T>.addAll(stream: Stream<T>) {
|
||||
for (item in stream) add(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [array] to this [MutableCollection].
|
||||
*/
|
||||
@@ -49,14 +41,6 @@ public fun <T> MutableCollection<in T>.removeAll(sequence: Sequence<T>) {
|
||||
for (item in sequence) remove(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements of the given [stream] from this [MutableCollection].
|
||||
*/
|
||||
deprecated("Use Sequence<T> instead of Stream<T>")
|
||||
public fun <T> MutableCollection<in T>.removeAll(stream: Stream<T>) {
|
||||
for (item in stream) remove(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements of the given [array] from this [MutableCollection].
|
||||
*/
|
||||
|
||||
@@ -21,14 +21,6 @@ public fun <T> Sequence<Sequence<T>>.flatten(): Sequence<T> {
|
||||
return MultiSequence(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence of all elements from all sequences in this sequence.
|
||||
*/
|
||||
deprecated("Use Sequence<T> instead of Stream<T>")
|
||||
public fun <T> Stream<Stream<T>>.flatten(): Stream<T> {
|
||||
return FlatteningStream(this, { it })
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements from all arrays in the given array.
|
||||
*/
|
||||
|
||||
@@ -3,35 +3,17 @@ package kotlin
|
||||
import java.util.*
|
||||
import kotlin.support.AbstractIterator
|
||||
|
||||
deprecated("Use Sequence<T> instead.")
|
||||
public interface Stream<out T> {
|
||||
/**
|
||||
* Returns an iterator that returns the values from the sequence.
|
||||
*/
|
||||
public fun iterator(): Iterator<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<out T> : Stream<T>
|
||||
|
||||
/**
|
||||
* Converts a stream to a sequence.
|
||||
*/
|
||||
public fun<T> Stream<T>.toSequence(): Sequence<T> = object : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> = this@toSequence.iterator()
|
||||
}
|
||||
|
||||
deprecated("Use sequenceOf() instead", ReplaceWith("sequenceOf(*elements)"))
|
||||
public fun <T> streamOf(vararg elements: T): Stream<T> = elements.stream()
|
||||
|
||||
deprecated("Use sequenceOf() instead", ReplaceWith("sequenceOf(progression)"))
|
||||
public fun <T> streamOf(progression: Progression<T>): Stream<T> = object : Stream<T> {
|
||||
override fun iterator(): Iterator<T> = progression.iterator()
|
||||
public interface Sequence<out T> {
|
||||
/**
|
||||
* Returns an iterator that returns the values from the sequence.
|
||||
*/
|
||||
public fun iterator(): Iterator<T>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,17 +52,10 @@ public fun <T> sequenceOf(progression: Progression<T>): Sequence<T> = object : S
|
||||
*/
|
||||
public fun <T> emptySequence(): Sequence<T> = EmptySequence
|
||||
|
||||
deprecated("Remove in M13 with streams.")
|
||||
private fun <T> emptyStream(): Stream<T> = EmptySequence
|
||||
|
||||
private object EmptySequence : Sequence<Nothing> {
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
}
|
||||
|
||||
deprecated("Use FilteringSequence<T> instead")
|
||||
public class FilteringStream<T>(stream: Stream<T>, sendWhen: Boolean = true, predicate: (T) -> Boolean)
|
||||
: Stream<T> by FilteringSequence<T>(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<T>(private val sequence: Sequence<T>,
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use TransformingSequence<T> instead")
|
||||
public class TransformingStream<T, R>(stream: Stream<T>, transformer: (T) -> R)
|
||||
: Stream<R> by TransformingSequence<T, R>(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<T>, private val transformer: (T) -> R
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use TransformingIndexedSequence<T> instead")
|
||||
public class TransformingIndexedStream<T, R>(stream: Stream<T>, transformer: (Int, T) -> R)
|
||||
: Stream<R> by TransformingIndexedSequence<T, R>(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<T>, private val transformer: (Int, T)
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use IndexingSequence<T> instead")
|
||||
public class IndexingStream<T>(stream: Stream<T>)
|
||||
: Stream<IndexedValue<T>> 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<T>) : Sequence<IndexedValue<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use MergingSequence<T> instead")
|
||||
public class MergingStream<T1, T2, V>(stream1: Stream<T1>, stream2: Stream<T2>, transform: (T1, T2) -> V)
|
||||
: Stream<V> 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<T> instead")
|
||||
public class FlatteningStream<T, R>(stream: Stream<T>, transformer: (T) -> Stream<R>)
|
||||
: Stream<R> 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<T, R>
|
||||
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<T> instead")
|
||||
public class Multistream<T>(stream: Stream<Stream<T>>)
|
||||
: Stream<T> 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<T>
|
||||
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<T>>) : Sequence<T> {
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use TakeSequence<T> instead")
|
||||
public class TakeStream<T>(stream: Stream<T>, count: Int)
|
||||
: Stream<T> 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<T> instead")
|
||||
public class TakeWhileStream<T>(stream: Stream<T>, predicate: (T) -> Boolean) : Stream<T> by TakeWhileSequence<T>(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<T> instead")
|
||||
public class DropStream<T>(stream: Stream<T>, count: Int)
|
||||
: Stream<T> by DropSequence<T>(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<T> instead")
|
||||
public class DropWhileStream<T>(stream: Stream<T>, predicate: (T) -> Boolean) : Stream<T> by DropWhileSequence<T>(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<T, K>(private val source: Stream<T>, private val keySelector : (T) -> K) : Stream<T> by DistinctSequence<T, K>(source.toSequence(), keySelector)
|
||||
|
||||
private class DistinctSequence<T, K>(private val source : Sequence<T>, private val keySelector : (T) -> K) : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> = DistinctIterator(source.iterator(), keySelector)
|
||||
}
|
||||
@@ -624,9 +558,6 @@ public fun <T : Any> sequence(nextFunction: () -> T?): Sequence<T> {
|
||||
return GeneratorSequence(nextFunction, { nextFunction() }).constrainOnce()
|
||||
}
|
||||
|
||||
deprecated("Use sequence() instead", ReplaceWith("sequence(nextFunction)"))
|
||||
public fun <T : Any> stream(nextFunction: () -> T?): Sequence<T> = 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 <T : Any> sequence(initialValue: T, nextFunction: (T) -> T
|
||||
*/
|
||||
public fun <T: Any> sequence(initialValueFunction: () -> T?, nextFunction: (T) -> T?): Sequence<T> =
|
||||
GeneratorSequence(initialValueFunction, nextFunction)
|
||||
|
||||
deprecated("Use sequence() instead", ReplaceWith("sequence(initialValue, nextFunction)"))
|
||||
public /*inline*/ fun <T : Any> stream(initialValue: T, nextFunction: (T) -> T?): Sequence<T> = sequence(initialValue, nextFunction)
|
||||
|
||||
@@ -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 <T:Any> iterate(nextFunction: () -> T?) : Iterator<T> {
|
||||
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 <T: Any> iterate(initialValue: T, nextFunction: (T) -> T?): Iterator<T> =
|
||||
iterate(nextFunction.toGenerator(initialValue))
|
||||
|
||||
/**
|
||||
* Returns an iterator whose values are pairs composed of values produced by given pair of iterators
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T, S> Iterator<T>.zip(iterator: Iterator<S>): Iterator<Pair<T, S>> = PairIterator(this, iterator)
|
||||
|
||||
/**
|
||||
* Returns an iterator shifted to right by the given number of elements
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.skip(n: Int): Iterator<T> = SkippingIterator(this, n)
|
||||
|
||||
deprecated("Use FilteringStream<T> instead")
|
||||
public class FilterIterator<T>(private val iterator: Iterator<T>, private val predicate: (T) -> Boolean) :
|
||||
AbstractIterator<T>() {
|
||||
override protected fun computeNext(): Unit {
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
if ((predicate)(next)) {
|
||||
setNext(next)
|
||||
return
|
||||
}
|
||||
}
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use FilteringStream<T> instead")
|
||||
public class FilterNotNullIterator<T : Any>(private val iterator: Iterator<T?>?) : AbstractIterator<T>() {
|
||||
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<T> instead")
|
||||
public class MapIterator<T, R>(private val iterator: Iterator<T>, private val transform: (T) -> R) :
|
||||
AbstractIterator<R>() {
|
||||
override protected fun computeNext(): Unit {
|
||||
if (iterator.hasNext()) {
|
||||
setNext((transform)(iterator.next()))
|
||||
} else {
|
||||
done()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use FlatteningStream<T> instead")
|
||||
public class FlatMapIterator<T, R>(private val iterator: Iterator<T>, private val transform: (T) -> Iterator<R>) :
|
||||
AbstractIterator<R>() {
|
||||
private var transformed: Iterator<R> = iterate<R> { 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<T> instead")
|
||||
public class TakeWhileIterator<T>(private val iterator: Iterator<T>, private val predicate: (T) -> Boolean) :
|
||||
AbstractIterator<T>() {
|
||||
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<T> instead")
|
||||
public class FunctionIterator<T : Any>(private val nextFunction: () -> T?) : AbstractIterator<T>() {
|
||||
|
||||
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<T> instead")
|
||||
public fun CompositeIterator<T>(vararg iterators: Iterator<T>): CompositeIterator<T> = CompositeIterator(iterators.iterator())
|
||||
|
||||
deprecated("Use Multistream<T> instead")
|
||||
public class CompositeIterator<T>(private val iterators: Iterator<Iterator<T>>) : AbstractIterator<T>() {
|
||||
|
||||
private var currentIter: Iterator<T>? = 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<T>(private val value: T) : AbstractIterator<T>() {
|
||||
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<T>(private val iterator: Iterator<T>) : Iterator<Pair<Int, T>> {
|
||||
private var index: Int = 0
|
||||
|
||||
override fun next(): Pair<Int, T> {
|
||||
return Pair(index++, iterator.next())
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return iterator.hasNext()
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use ZippingStream<T> instead.")
|
||||
public class PairIterator<T, S>(
|
||||
private val iterator1: Iterator<T>, private val iterator2: Iterator<S>
|
||||
): AbstractIterator<Pair<T, S>>() {
|
||||
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<T>(private val iterator: Iterator<T>, private val n: Int) : Iterator<T> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -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 <T, R : T> Iterator<T>.filterIsInstance(klass: Class<R>): Iterator<R> = FilterIsIterator<T, R>(this, klass)
|
||||
|
||||
deprecated("Use streams for lazy collection operations.")
|
||||
public class FilterIsIterator<T, R : T>(private val iterator: Iterator<T>, private val klass: Class<R>) :
|
||||
AbstractIterator<R>() {
|
||||
override protected fun computeNext(): Unit {
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
if (klass.isInstance(next)) {
|
||||
setNext(next as R)
|
||||
return
|
||||
}
|
||||
}
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.drop(n: Int) : List<T> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.dropWhile(predicate: (T) -> Boolean) : List<T> {
|
||||
return dropWhileTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, L: MutableList<in T>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.filter(predicate: (T) -> Boolean) : Iterator<T> {
|
||||
return FilterIterator<T>(this, predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over elements which don't match the given *predicate*
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.filterNot(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) predicate: (T) -> Boolean) : Iterator<T> {
|
||||
return filter {!predicate(it)}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over non-*null* elements
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T:Any> Iterator<T?>.filterNotNull() : Iterator<T> {
|
||||
return FilterNotNullIterator(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all non-*null* elements into the given list
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T:Any, C: MutableCollection<in T>> Iterator<T?>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T:Any> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T, R> Iterator<T>.flatMap(transform: (T) -> Iterator<R>) : Iterator<R> {
|
||||
return FlatMapIterator<T, R>(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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterator<T>.flatMapTo(result: C, transform: (T) -> Iterable<R>) : 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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, R> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, K> Iterator<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, K> Iterator<T>.groupByTo(result: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<T>() }
|
||||
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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T, R> Iterator<T>.map(transform : (T) -> R) : Iterator<R> {
|
||||
return MapIterator<T, R>(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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T: Comparable<T>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <R: Comparable<R>, T: Any> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T: Comparable<T>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <R: Comparable<R>, T: Any> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<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)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.plus(collection: Iterable<T>) : Iterator<T> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.plus(element: T) : Iterator<T> {
|
||||
return CompositeIterator<T>(this, SingleIterator(element))
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.plus(iterator: Iterator<T>) : Iterator<T> {
|
||||
return CompositeIterator<T>(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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T:Any> Iterator<T?>.requireNoNulls() : Iterator<T> {
|
||||
return map<T?, T>{
|
||||
if (it == null) throw IllegalArgumentException("null element in iterator $this") else it
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.reverse() : List<T> {
|
||||
val list = toCollection(ArrayList<T>())
|
||||
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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, R: Comparable<R>> Iterator<T>.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) f: (T) -> R) : List<T> {
|
||||
val sortedList = toCollection(ArrayList<T>())
|
||||
val sortBy: Comparator<T> = comparator<T> {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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.take(n: Int) : Iterator<T> {
|
||||
var count = n
|
||||
return takeWhile{ --count >= 0 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator restricted to the first elements that match the given *predicate*
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.takeWhile(predicate: (T) -> Boolean) : Iterator<T> {
|
||||
return TakeWhileIterator<T>(this, predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.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<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T, C: MutableCollection<in T>> Iterator<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[ArrayList]]
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.toArrayList() : ArrayList<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[HashSet]]
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.toHashSet() : HashSet<T> {
|
||||
return toCollection(HashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
|
||||
public fun <T> Iterator<T>.withIndices() : Iterator<Pair<Int, T>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
@@ -269,11 +269,6 @@ public fun Sequence<String>.join(separator: String = ", ", prefix: String = "",
|
||||
return joinToString(separator, prefix, postfix, limit, truncated)
|
||||
}
|
||||
|
||||
deprecated("Migrate to using Sequence<T> and respective functions")
|
||||
public fun Stream<String>.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.
|
||||
|
||||
Reference in New Issue
Block a user