Sequence operation classification regarding their statefulness and laziness.
#KT-16994 Fixed
This commit is contained in:
@@ -12,32 +12,44 @@ import kotlin.comparisons.*
|
||||
|
||||
/**
|
||||
* Returns `true` if [element] is found in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header operator fun <@kotlin.internal.OnlyInputTypes T> Sequence<T>.contains(element: T): Boolean
|
||||
|
||||
/**
|
||||
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.elementAt(index: Int): T
|
||||
|
||||
/**
|
||||
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T
|
||||
|
||||
/**
|
||||
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.elementAtOrNull(index: Int): T?
|
||||
|
||||
/**
|
||||
* Returns the first element matching the given [predicate], or `null` if no such element was found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public header inline fun <T> Sequence<T>.find(predicate: (T) -> Boolean): T?
|
||||
|
||||
/**
|
||||
* Returns the last element matching the given [predicate], or `null` if no such element was found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public header inline fun <T> Sequence<T>.findLast(predicate: (T) -> Boolean): T?
|
||||
@@ -45,99 +57,137 @@ public header inline fun <T> Sequence<T>.findLast(predicate: (T) -> Boolean): T?
|
||||
/**
|
||||
* Returns first element.
|
||||
* @throws [NoSuchElementException] if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.first(): T
|
||||
|
||||
/**
|
||||
* Returns the first element matching the given [predicate].
|
||||
* @throws [NoSuchElementException] if no such element is found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T
|
||||
|
||||
/**
|
||||
* Returns the first element, or `null` if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.firstOrNull(): T?
|
||||
|
||||
/**
|
||||
* Returns the first element matching the given [predicate], or `null` if element was not found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.firstOrNull(predicate: (T) -> Boolean): T?
|
||||
|
||||
/**
|
||||
* Returns first index of [element], or -1 if the sequence does not contain element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <@kotlin.internal.OnlyInputTypes T> Sequence<T>.indexOf(element: T): Int
|
||||
|
||||
/**
|
||||
* Returns index of the first element matching the given [predicate], or -1 if the sequence does not contain such element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.indexOfFirst(predicate: (T) -> Boolean): Int
|
||||
|
||||
/**
|
||||
* Returns index of the last element matching the given [predicate], or -1 if the sequence does not contain such element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.indexOfLast(predicate: (T) -> Boolean): Int
|
||||
|
||||
/**
|
||||
* Returns the last element.
|
||||
* @throws [NoSuchElementException] if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.last(): T
|
||||
|
||||
/**
|
||||
* Returns the last element matching the given [predicate].
|
||||
* @throws [NoSuchElementException] if no such element is found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.last(predicate: (T) -> Boolean): T
|
||||
|
||||
/**
|
||||
* Returns last index of [element], or -1 if the sequence does not contain element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <@kotlin.internal.OnlyInputTypes T> Sequence<T>.lastIndexOf(element: T): Int
|
||||
|
||||
/**
|
||||
* Returns the last element, or `null` if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.lastOrNull(): T?
|
||||
|
||||
/**
|
||||
* Returns the last element matching the given [predicate], or `null` if no such element was found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.lastOrNull(predicate: (T) -> Boolean): T?
|
||||
|
||||
/**
|
||||
* Returns the single element, or throws an exception if the sequence is empty or has more than one element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.single(): T
|
||||
|
||||
/**
|
||||
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.single(predicate: (T) -> Boolean): T
|
||||
|
||||
/**
|
||||
* Returns single element, or `null` if the sequence is empty or has more than one element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.singleOrNull(): T?
|
||||
|
||||
/**
|
||||
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.singleOrNull(predicate: (T) -> Boolean): T?
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements except first [n] elements.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.drop(n: Int): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements except first elements that satisfy the given [predicate].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.dropWhile(predicate: (T) -> Boolean): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing only elements matching the given [predicate].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T>
|
||||
|
||||
@@ -145,6 +195,8 @@ public header fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T>
|
||||
* Returns a sequence containing only elements matching the given [predicate].
|
||||
* @param [predicate] function that takes the index of an element and the element itself
|
||||
* and returns the result of predicate evaluation on the element.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean): Sequence<T>
|
||||
|
||||
@@ -152,76 +204,106 @@ public header fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Bo
|
||||
* Appends all elements matching the given [predicate] to the given [destination].
|
||||
* @param [predicate] function that takes the index of an element and the element itself
|
||||
* and returns the result of predicate evaluation on the element.
|
||||
*
|
||||
* The operation is _terminal_ and _nearly stateless_.
|
||||
*/
|
||||
public header inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements that are instances of specified type parameter R.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.internal.NoInfer R>
|
||||
|
||||
/**
|
||||
* Appends all elements that are instances of specified type parameter R to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsInstanceTo(destination: C): C
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements not matching the given [predicate].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.filterNot(predicate: (T) -> Boolean): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements that are not `null`.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T : Any> Sequence<T?>.filterNotNull(): Sequence<T>
|
||||
|
||||
/**
|
||||
* Appends all elements that are not `null` to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header fun <C : MutableCollection<in T>, T : Any> Sequence<T?>.filterNotNullTo(destination: C): C
|
||||
|
||||
/**
|
||||
* Appends all elements not matching the given [predicate] to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterNotTo(destination: C, predicate: (T) -> Boolean): C
|
||||
|
||||
/**
|
||||
* Appends all elements matching the given [predicate] to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destination: C, predicate: (T) -> Boolean): C
|
||||
|
||||
/**
|
||||
* Returns a sequence containing first [n] elements.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.take(n: Int): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing first elements satisfying the given [predicate].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.takeWhile(predicate: (T) -> Boolean): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence that yields elements of this sequence sorted according to their natural sort order.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header fun <T : Comparable<T>> Sequence<T>.sorted(): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [selector] function.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header inline fun <T, R : Comparable<R>> Sequence<T>.sortedBy(crossinline selector: (T) -> R?): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [selector] function.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header inline fun <T, R : Comparable<R>> Sequence<T>.sortedByDescending(crossinline selector: (T) -> R?): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence that yields elements of this sequence sorted descending according to their natural sort order.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header fun <T : Comparable<T>> Sequence<T>.sortedDescending(): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence that yields elements of this sequence sorted according to the specified [comparator].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.sortedWith(comparator: Comparator<in T>): Sequence<T>
|
||||
|
||||
@@ -232,6 +314,8 @@ public header fun <T> Sequence<T>.sortedWith(comparator: Comparator<in T>): Sequ
|
||||
* If any of two pairs would have the same key the last one gets added to the map.
|
||||
*
|
||||
* The returned map preserves the entry iteration order of the original sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, V> Sequence<T>.associate(transform: (T) -> Pair<K, V>): Map<K, V>
|
||||
|
||||
@@ -242,6 +326,8 @@ public header inline fun <T, K, V> Sequence<T>.associate(transform: (T) -> Pair<
|
||||
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
|
||||
*
|
||||
* The returned map preserves the entry iteration order of the original sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K> Sequence<T>.associateBy(keySelector: (T) -> K): Map<K, T>
|
||||
|
||||
@@ -251,6 +337,8 @@ public header inline fun <T, K> Sequence<T>.associateBy(keySelector: (T) -> K):
|
||||
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
|
||||
*
|
||||
* The returned map preserves the entry iteration order of the original sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, V> Sequence<T>.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, V>
|
||||
|
||||
@@ -260,6 +348,8 @@ public header inline fun <T, K, V> Sequence<T>.associateBy(keySelector: (T) -> K
|
||||
* and value is the element itself.
|
||||
*
|
||||
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, M : MutableMap<in K, in T>> Sequence<T>.associateByTo(destination: M, keySelector: (T) -> K): M
|
||||
|
||||
@@ -269,6 +359,8 @@ public header inline fun <T, K, M : MutableMap<in K, in T>> Sequence<T>.associat
|
||||
* and value is provided by the [valueTransform] function applied to elements of the given sequence.
|
||||
*
|
||||
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.associateByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M
|
||||
|
||||
@@ -277,26 +369,36 @@ public header inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.assoc
|
||||
* provided by [transform] function applied to each element of the given sequence.
|
||||
*
|
||||
* If any of two pairs would have the same key the last one gets added to the map.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.associateTo(destination: M, transform: (T) -> Pair<K, V>): M
|
||||
|
||||
/**
|
||||
* Appends all elements to the given [destination] collection.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T, C : MutableCollection<in T>> Sequence<T>.toCollection(destination: C): C
|
||||
|
||||
/**
|
||||
* Returns a [HashSet] of all elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.toHashSet(): HashSet<T>
|
||||
|
||||
/**
|
||||
* Returns a [List] containing all elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.toList(): List<T>
|
||||
|
||||
/**
|
||||
* Returns a [MutableList] filled with all elements of this sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.toMutableList(): MutableList<T>
|
||||
|
||||
@@ -304,16 +406,22 @@ public header fun <T> Sequence<T>.toMutableList(): MutableList<T>
|
||||
* Returns a [Set] of all elements.
|
||||
*
|
||||
* The returned set preserves the element iteration order of the original sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.toSet(): Set<T>
|
||||
|
||||
/**
|
||||
* Returns a single sequence of all elements from results of [transform] function being invoked on each element of original sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T, R> Sequence<T>.flatMap(transform: (T) -> Sequence<R>): Sequence<R>
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of [transform] function being invoked on each element of original sequence, to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(destination: C, transform: (T) -> Sequence<R>): C
|
||||
|
||||
@@ -324,6 +432,8 @@ public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMap
|
||||
* The returned map preserves the entry iteration order of the keys produced from the original sequence.
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
*/
|
||||
public header inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<K, List<T>>
|
||||
|
||||
@@ -335,6 +445,8 @@ public header inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<
|
||||
* The returned map preserves the entry iteration order of the keys produced from the original sequence.
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
*/
|
||||
public header inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, List<V>>
|
||||
|
||||
@@ -345,6 +457,8 @@ public header inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, va
|
||||
* @return The [destination] map.
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
*/
|
||||
public header inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K): M
|
||||
|
||||
@@ -356,6 +470,8 @@ public header inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T
|
||||
* @return The [destination] map.
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
*/
|
||||
public header inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M
|
||||
|
||||
@@ -364,6 +480,8 @@ public header inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Sequenc
|
||||
* using the specified [keySelector] function to extract a key from each element.
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupingByEachCount
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public header inline fun <T, K> Sequence<T>.groupingBy(crossinline keySelector: (T) -> K): Grouping<T, K>
|
||||
@@ -371,6 +489,8 @@ public header inline fun <T, K> Sequence<T>.groupingBy(crossinline keySelector:
|
||||
/**
|
||||
* Returns a sequence containing the results of applying the given [transform] function
|
||||
* to each element in the original sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R>
|
||||
|
||||
@@ -379,6 +499,8 @@ public header fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R>
|
||||
* to each element and its index in the original sequence.
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Sequence<R>
|
||||
|
||||
@@ -387,6 +509,8 @@ public header fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R)
|
||||
* to each element and its index in the original sequence.
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T) -> R?): Sequence<R>
|
||||
|
||||
@@ -395,6 +519,8 @@ public header fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index:
|
||||
* and appends only the non-null results to the given [destination].
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*
|
||||
* The operation is _terminal_ and _nearly stateless_.
|
||||
*/
|
||||
public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C
|
||||
|
||||
@@ -403,29 +529,39 @@ public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.m
|
||||
* and appends the results to the given [destination].
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*
|
||||
* The operation is _terminal_ and _nearly stateless_.
|
||||
*/
|
||||
public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C
|
||||
|
||||
/**
|
||||
* Returns a sequence containing only the non-null results of applying the given [transform] function
|
||||
* to each element in the original sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T, R : Any> Sequence<T>.mapNotNull(transform: (T) -> R?): Sequence<R>
|
||||
|
||||
/**
|
||||
* Applies the given [transform] function to each element in the original sequence
|
||||
* and appends only the non-null results to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapNotNullTo(destination: C, transform: (T) -> R?): C
|
||||
|
||||
/**
|
||||
* Applies the given [transform] function to each element of the original sequence
|
||||
* and appends the results to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
*/
|
||||
public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destination: C, transform: (T) -> R): C
|
||||
|
||||
/**
|
||||
* Returns a sequence of [IndexedValue] for each element of the original sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.withIndex(): Sequence<IndexedValue<T>>
|
||||
|
||||
@@ -433,6 +569,8 @@ public header fun <T> Sequence<T>.withIndex(): Sequence<IndexedValue<T>>
|
||||
* Returns a sequence containing only distinct elements from the given sequence.
|
||||
*
|
||||
* The elements in the resulting sequence are in the same order as they were in the source sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.distinct(): Sequence<T>
|
||||
|
||||
@@ -441,6 +579,8 @@ public header fun <T> Sequence<T>.distinct(): Sequence<T>
|
||||
* having distinct keys returned by the given [selector] function.
|
||||
*
|
||||
* The elements in the resulting sequence are in the same order as they were in the source sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header fun <T, K> Sequence<T>.distinctBy(selector: (T) -> K): Sequence<T>
|
||||
|
||||
@@ -448,36 +588,50 @@ public header fun <T, K> Sequence<T>.distinctBy(selector: (T) -> K): Sequence<T>
|
||||
* Returns a mutable set containing all distinct elements from the given sequence.
|
||||
*
|
||||
* The returned set preserves the element iteration order of the original sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.toMutableSet(): MutableSet<T>
|
||||
|
||||
/**
|
||||
* Returns `true` if all elements match the given [predicate].
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean
|
||||
|
||||
/**
|
||||
* Returns `true` if sequence has at least one element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.any(): Boolean
|
||||
|
||||
/**
|
||||
* Returns `true` if at least one element matches the given [predicate].
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.any(predicate: (T) -> Boolean): Boolean
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.count(): Int
|
||||
|
||||
/**
|
||||
* Returns the number of elements matching the given [predicate].
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.count(predicate: (T) -> Boolean): Int
|
||||
|
||||
/**
|
||||
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R> Sequence<T>.fold(initial: R, operation: (acc: R, T) -> R): R
|
||||
|
||||
@@ -486,11 +640,15 @@ public header inline fun <T, R> Sequence<T>.fold(initial: R, operation: (acc: R,
|
||||
* to current accumulator value and each element with its index in the original sequence.
|
||||
* @param [operation] function that takes the index of an element, current accumulator value
|
||||
* and the element itself, and calculates the next accumulator value.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R> Sequence<T>.foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): R
|
||||
|
||||
/**
|
||||
* Performs the given [action] on each element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.forEach(action: (T) -> Unit): Unit
|
||||
|
||||
@@ -498,6 +656,8 @@ public header inline fun <T> Sequence<T>.forEach(action: (T) -> Unit): Unit
|
||||
* Performs the given [action] on each element, providing sequential index with the element.
|
||||
* @param [action] function that takes the index of an element and the element itself
|
||||
* and performs the desired action on the element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.forEachIndexed(action: (index: Int, T) -> Unit): Unit
|
||||
|
||||
@@ -505,6 +665,8 @@ public header inline fun <T> Sequence<T>.forEachIndexed(action: (index: Int, T)
|
||||
* Returns the largest element or `null` if there are no elements.
|
||||
*
|
||||
* If any of elements is `NaN` returns `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public header fun Sequence<Double>.max(): Double?
|
||||
@@ -513,22 +675,30 @@ public header fun Sequence<Double>.max(): Double?
|
||||
* Returns the largest element or `null` if there are no elements.
|
||||
*
|
||||
* If any of elements is `NaN` returns `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public header fun Sequence<Float>.max(): Float?
|
||||
|
||||
/**
|
||||
* Returns the largest element or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T : Comparable<T>> Sequence<T>.max(): T?
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T) -> R): T?
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T?
|
||||
|
||||
@@ -536,6 +706,8 @@ public header fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T?
|
||||
* Returns the smallest element or `null` if there are no elements.
|
||||
*
|
||||
* If any of elements is `NaN` returns `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public header fun Sequence<Double>.min(): Double?
|
||||
@@ -544,43 +716,59 @@ public header fun Sequence<Double>.min(): Double?
|
||||
* Returns the smallest element or `null` if there are no elements.
|
||||
*
|
||||
* If any of elements is `NaN` returns `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public header fun Sequence<Float>.min(): Float?
|
||||
|
||||
/**
|
||||
* Returns the smallest element or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T : Comparable<T>> Sequence<T>.min(): T?
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R : Comparable<R>> Sequence<T>.minBy(selector: (T) -> R): T?
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T?
|
||||
|
||||
/**
|
||||
* Returns `true` if the sequence has no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.none(): Boolean
|
||||
|
||||
/**
|
||||
* Returns `true` if no elements match the given [predicate].
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.none(predicate: (T) -> Boolean): Boolean
|
||||
|
||||
/**
|
||||
* Returns a sequence which performs the given [action] on each element of the original sequence as they pass though it.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public header fun <T> Sequence<T>.onEach(action: (T) -> Unit): Sequence<T>
|
||||
|
||||
/**
|
||||
* Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <S, T: S> Sequence<T>.reduce(operation: (acc: S, T) -> S): S
|
||||
|
||||
@@ -589,26 +777,36 @@ public header inline fun <S, T: S> Sequence<T>.reduce(operation: (acc: S, T) ->
|
||||
* to current accumulator value and each element with its index in the original sequence.
|
||||
* @param [operation] function that takes the index of an element, current accumulator value
|
||||
* and the element itself and calculates the next accumulator value.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <S, T: S> Sequence<T>.reduceIndexed(operation: (index: Int, acc: S, T) -> S): S
|
||||
|
||||
/**
|
||||
* Returns the sum of all values produced by [selector] function applied to each element in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.sumBy(selector: (T) -> Int): Int
|
||||
|
||||
/**
|
||||
* Returns the sum of all values produced by [selector] function applied to each element in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.sumByDouble(selector: (T) -> Double): Double
|
||||
|
||||
/**
|
||||
* Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T : Any> Sequence<T?>.requireNoNulls(): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.minus(element: T): Sequence<T>
|
||||
|
||||
@@ -617,6 +815,8 @@ public header operator fun <T> Sequence<T>.minus(element: T): Sequence<T>
|
||||
*
|
||||
* Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from
|
||||
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.minus(elements: Array<out T>): Sequence<T>
|
||||
|
||||
@@ -625,6 +825,8 @@ public header operator fun <T> Sequence<T>.minus(elements: Array<out T>): Sequen
|
||||
*
|
||||
* Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from
|
||||
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.minus(elements: Iterable<T>): Sequence<T>
|
||||
|
||||
@@ -633,11 +835,15 @@ public header operator fun <T> Sequence<T>.minus(elements: Iterable<T>): Sequenc
|
||||
*
|
||||
* Note that the source sequence and the sequence being subtracted are iterated only when an `iterator` is requested from
|
||||
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
|
||||
*
|
||||
* The operation is _intermediate_ for this sequence and _terminal_ and _stateful_ for the [elements] sequence.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.minus(elements: Sequence<T>): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public header inline fun <T> Sequence<T>.minusElement(element: T): Sequence<T>
|
||||
@@ -646,11 +852,15 @@ public header inline fun <T> Sequence<T>.minusElement(element: T): Sequence<T>
|
||||
* Splits the original sequence into pair of lists,
|
||||
* where *first* list contains elements for which [predicate] yielded `true`,
|
||||
* while *second* list contains elements for which [predicate] yielded `false`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T> Sequence<T>.partition(predicate: (T) -> Boolean): Pair<List<T>, List<T>>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements of the original sequence and then the given [element].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.plus(element: T): Sequence<T>
|
||||
|
||||
@@ -659,6 +869,8 @@ public header operator fun <T> Sequence<T>.plus(element: T): Sequence<T>
|
||||
*
|
||||
* Note that the source sequence and the array being added are iterated only when an `iterator` is requested from
|
||||
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.plus(elements: Array<out T>): Sequence<T>
|
||||
|
||||
@@ -667,6 +879,8 @@ public header operator fun <T> Sequence<T>.plus(elements: Array<out T>): Sequenc
|
||||
*
|
||||
* Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from
|
||||
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.plus(elements: Iterable<T>): Sequence<T>
|
||||
|
||||
@@ -675,11 +889,15 @@ public header operator fun <T> Sequence<T>.plus(elements: Iterable<T>): Sequence
|
||||
*
|
||||
* Note that the source sequence and the sequence being added are iterated only when an `iterator` is requested from
|
||||
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.plus(elements: Sequence<T>): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements of the original sequence and then the given [element].
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public header inline fun <T> Sequence<T>.plusElement(element: T): Sequence<T>
|
||||
@@ -687,11 +905,15 @@ public header inline fun <T> Sequence<T>.plusElement(element: T): Sequence<T>
|
||||
/**
|
||||
* Returns a sequence of pairs built from elements of both sequences with same indexes.
|
||||
* Resulting sequence has length of shortest input sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header infix fun <T, R> Sequence<T>.zip(other: Sequence<R>): Sequence<Pair<T, R>>
|
||||
|
||||
/**
|
||||
* Returns a sequence of values built from elements of both collections with same indexes using provided [transform]. Resulting sequence has length of shortest input sequences.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T, R, V> Sequence<T>.zip(other: Sequence<R>, transform: (a: T, b: R) -> V): Sequence<V>
|
||||
|
||||
@@ -700,6 +922,8 @@ public header fun <T, R, V> Sequence<T>.zip(other: Sequence<R>, transform: (a: T
|
||||
*
|
||||
* 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 "...").
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
@@ -720,6 +944,8 @@ public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: CharSequ
|
||||
*
|
||||
* 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 "...").
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
@@ -738,72 +964,96 @@ public header inline fun <T> Sequence<T>.asSequence(): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns an average value of elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("averageOfByte")
|
||||
public header fun Sequence<Byte>.average(): Double
|
||||
|
||||
/**
|
||||
* Returns an average value of elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("averageOfShort")
|
||||
public header fun Sequence<Short>.average(): Double
|
||||
|
||||
/**
|
||||
* Returns an average value of elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("averageOfInt")
|
||||
public header fun Sequence<Int>.average(): Double
|
||||
|
||||
/**
|
||||
* Returns an average value of elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("averageOfLong")
|
||||
public header fun Sequence<Long>.average(): Double
|
||||
|
||||
/**
|
||||
* Returns an average value of elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("averageOfFloat")
|
||||
public header fun Sequence<Float>.average(): Double
|
||||
|
||||
/**
|
||||
* Returns an average value of elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("averageOfDouble")
|
||||
public header fun Sequence<Double>.average(): Double
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("sumOfByte")
|
||||
public header fun Sequence<Byte>.sum(): Int
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("sumOfShort")
|
||||
public header fun Sequence<Short>.sum(): Int
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("sumOfInt")
|
||||
public header fun Sequence<Int>.sum(): Int
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("sumOfLong")
|
||||
public header fun Sequence<Long>.sum(): Long
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("sumOfFloat")
|
||||
public header fun Sequence<Float>.sum(): Float
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the sequence.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@kotlin.jvm.JvmName("sumOfDouble")
|
||||
public header fun Sequence<Double>.sum(): Double
|
||||
|
||||
Reference in New Issue
Block a user