Remove 'nearly_stateless' category, do not mention statefulness for terminal operations.
#KT-16994
This commit is contained in:
@@ -329,7 +329,7 @@ public 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.drop(n: Int): Sequence<T> {
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
@@ -363,7 +363,7 @@ public fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T> {
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean): Sequence<T> {
|
||||
// TODO: Rewrite with generalized MapFilterIndexingSequence
|
||||
@@ -375,7 +375,7 @@ public fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean):
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C {
|
||||
forEachIndexed { index, element ->
|
||||
@@ -397,7 +397,7 @@ public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.i
|
||||
/**
|
||||
* Appends all elements that are instances of specified type parameter R to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsInstanceTo(destination: C): C {
|
||||
for (element in this) if (element is R) destination.add(element)
|
||||
@@ -426,7 +426,7 @@ public 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public fun <C : MutableCollection<in T>, T : Any> Sequence<T?>.filterNotNullTo(destination: C): C {
|
||||
for (element in this) if (element != null) destination.add(element)
|
||||
@@ -436,7 +436,7 @@ public fun <C : MutableCollection<in T>, T : Any> Sequence<T?>.filterNotNullTo(d
|
||||
/**
|
||||
* Appends all elements not matching the given [predicate] to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterNotTo(destination: C, predicate: (T) -> Boolean): C {
|
||||
for (element in this) if (!predicate(element)) destination.add(element)
|
||||
@@ -446,7 +446,7 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterNotTo(desti
|
||||
/**
|
||||
* Appends all elements matching the given [predicate] to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destination: C, predicate: (T) -> Boolean): C {
|
||||
for (element in this) if (predicate(element)) destination.add(element)
|
||||
@@ -456,7 +456,7 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destinat
|
||||
/**
|
||||
* Returns a sequence containing first [n] elements.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.take(n: Int): Sequence<T> {
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
@@ -683,7 +683,7 @@ public 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(destination: C, transform: (T) -> Sequence<R>): C {
|
||||
for (element in this) {
|
||||
@@ -701,7 +701,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(dest
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<K, List<T>> {
|
||||
return groupByTo(LinkedHashMap<K, MutableList<T>>(), keySelector)
|
||||
@@ -716,7 +716,7 @@ public inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<K, List
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, List<V>> {
|
||||
return groupByTo(LinkedHashMap<K, MutableList<V>>(), keySelector, valueTransform)
|
||||
@@ -730,7 +730,7 @@ public inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, valueTran
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K): M {
|
||||
for (element in this) {
|
||||
@@ -750,7 +750,7 @@ public inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T>.group
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {
|
||||
for (element in this) {
|
||||
@@ -793,7 +793,7 @@ public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R> {
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Sequence<R> {
|
||||
return TransformingIndexedSequence(this, transform)
|
||||
@@ -805,7 +805,7 @@ public fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Seque
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T) -> R?): Sequence<R> {
|
||||
return TransformingIndexedSequence(this, transform).filterNotNull()
|
||||
@@ -817,7 +817,7 @@ public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T)
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C {
|
||||
forEachIndexed { index, element -> transform(index, element)?.let { destination.add(it) } }
|
||||
@@ -830,7 +830,7 @@ public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndex
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C {
|
||||
var index = 0
|
||||
@@ -853,7 +853,7 @@ public 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapNotNullTo(destination: C, transform: (T) -> R?): C {
|
||||
forEach { element -> transform(element)?.let { destination.add(it) } }
|
||||
@@ -864,7 +864,7 @@ public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapNotNu
|
||||
* 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destination: C, transform: (T) -> R): C {
|
||||
for (item in this)
|
||||
@@ -875,7 +875,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destinat
|
||||
/**
|
||||
* Returns a sequence of [IndexedValue] for each element of the original sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.withIndex(): Sequence<IndexedValue<T>> {
|
||||
return IndexingSequence(this)
|
||||
@@ -1311,7 +1311,7 @@ public 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public operator fun <T> Sequence<T>.minus(element: T): Sequence<T> {
|
||||
return object: Sequence<T> {
|
||||
@@ -1383,7 +1383,7 @@ public 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Sequence<T>.minusElement(element: T): Sequence<T> {
|
||||
|
||||
@@ -173,7 +173,7 @@ public header inline fun <T> Sequence<T>.singleOrNull(predicate: (T) -> Boolean)
|
||||
/**
|
||||
* Returns a sequence containing all elements except first [n] elements.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.drop(n: Int): Sequence<T>
|
||||
|
||||
@@ -196,7 +196,7 @@ public header fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T>
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean): Sequence<T>
|
||||
|
||||
@@ -205,7 +205,7 @@ public header fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Bo
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C
|
||||
|
||||
@@ -219,7 +219,7 @@ public header inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@k
|
||||
/**
|
||||
* Appends all elements that are instances of specified type parameter R to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsInstanceTo(destination: C): C
|
||||
|
||||
@@ -240,28 +240,28 @@ 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.take(n: Int): Sequence<T>
|
||||
|
||||
@@ -421,7 +421,7 @@ public header fun <T, R> Sequence<T>.flatMap(transform: (T) -> Sequence<R>): Seq
|
||||
/**
|
||||
* 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(destination: C, transform: (T) -> Sequence<R>): C
|
||||
|
||||
@@ -433,7 +433,7 @@ public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMap
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<K, List<T>>
|
||||
|
||||
@@ -446,7 +446,7 @@ public header inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, List<V>>
|
||||
|
||||
@@ -458,7 +458,7 @@ public header inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, va
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K): M
|
||||
|
||||
@@ -471,7 +471,7 @@ public header inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -500,7 +500,7 @@ public header fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R>
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Sequence<R>
|
||||
|
||||
@@ -510,7 +510,7 @@ public header fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R)
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T) -> R?): Sequence<R>
|
||||
|
||||
@@ -520,7 +520,7 @@ public header fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index:
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C
|
||||
|
||||
@@ -530,7 +530,7 @@ public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.m
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C
|
||||
|
||||
@@ -546,7 +546,7 @@ public header fun <T, R : Any> Sequence<T>.mapNotNull(transform: (T) -> R?): Seq
|
||||
* 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapNotNullTo(destination: C, transform: (T) -> R?): C
|
||||
|
||||
@@ -554,14 +554,14 @@ public header inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.m
|
||||
* 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header fun <T> Sequence<T>.withIndex(): Sequence<IndexedValue<T>>
|
||||
|
||||
@@ -806,7 +806,7 @@ 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public header operator fun <T> Sequence<T>.minus(element: T): Sequence<T>
|
||||
|
||||
@@ -843,7 +843,7 @@ public header operator fun <T> Sequence<T>.minus(elements: Sequence<T>): Sequenc
|
||||
/**
|
||||
* 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public header inline fun <T> Sequence<T>.minusElement(element: T): Sequence<T>
|
||||
|
||||
@@ -93,8 +93,8 @@ and extension functions for sequences.
|
||||
|
||||
The sequence operations can be classified into the following groups regarding their state requirements:
|
||||
|
||||
- _stateless_ – operations like [kotlin.sequences.Sequence.map], [kotlin.sequences.Sequence.filter], which process each element independently;
|
||||
- _nearly stateless_ – operations which require a small constant amount of state to process an element, for example [kotlin.sequences.Sequence.take] or [kotlin.sequences.Sequence.drop];
|
||||
- _stateless_ – operations which require no state and process each element independently like [kotlin.sequences.Sequence.map], [kotlin.sequences.Sequence.filter],
|
||||
or require a small constant amount of state to process an element, for example [kotlin.sequences.Sequence.take] or [kotlin.sequences.Sequence.drop];
|
||||
- _stateful_ – operations which require a significant amount of state, usually proportional to the number of elements in a sequence.
|
||||
|
||||
If the sequence operation returns another sequence, which is produced lazily, it's called _intermediate_, and otherwise the operation is _terminal_.
|
||||
|
||||
@@ -329,7 +329,7 @@ public 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.drop(n: Int): Sequence<T> {
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
@@ -363,7 +363,7 @@ public fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T> {
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean): Sequence<T> {
|
||||
// TODO: Rewrite with generalized MapFilterIndexingSequence
|
||||
@@ -375,7 +375,7 @@ public fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean):
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C {
|
||||
forEachIndexed { index, element ->
|
||||
@@ -397,7 +397,7 @@ public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.i
|
||||
/**
|
||||
* Appends all elements that are instances of specified type parameter R to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsInstanceTo(destination: C): C {
|
||||
for (element in this) if (element is R) destination.add(element)
|
||||
@@ -426,7 +426,7 @@ public 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public fun <C : MutableCollection<in T>, T : Any> Sequence<T?>.filterNotNullTo(destination: C): C {
|
||||
for (element in this) if (element != null) destination.add(element)
|
||||
@@ -436,7 +436,7 @@ public fun <C : MutableCollection<in T>, T : Any> Sequence<T?>.filterNotNullTo(d
|
||||
/**
|
||||
* Appends all elements not matching the given [predicate] to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterNotTo(destination: C, predicate: (T) -> Boolean): C {
|
||||
for (element in this) if (!predicate(element)) destination.add(element)
|
||||
@@ -446,7 +446,7 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterNotTo(desti
|
||||
/**
|
||||
* Appends all elements matching the given [predicate] to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_ and _stateless_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destination: C, predicate: (T) -> Boolean): C {
|
||||
for (element in this) if (predicate(element)) destination.add(element)
|
||||
@@ -456,7 +456,7 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destinat
|
||||
/**
|
||||
* Returns a sequence containing first [n] elements.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.take(n: Int): Sequence<T> {
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
@@ -705,7 +705,7 @@ public 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(destination: C, transform: (T) -> Sequence<R>): C {
|
||||
for (element in this) {
|
||||
@@ -723,7 +723,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(dest
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<K, List<T>> {
|
||||
return groupByTo(LinkedHashMap<K, MutableList<T>>(), keySelector)
|
||||
@@ -738,7 +738,7 @@ public inline fun <T, K> Sequence<T>.groupBy(keySelector: (T) -> K): Map<K, List
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, List<V>> {
|
||||
return groupByTo(LinkedHashMap<K, MutableList<V>>(), keySelector, valueTransform)
|
||||
@@ -752,7 +752,7 @@ public inline fun <T, K, V> Sequence<T>.groupBy(keySelector: (T) -> K, valueTran
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupBy
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K): M {
|
||||
for (element in this) {
|
||||
@@ -772,7 +772,7 @@ public inline fun <T, K, M : MutableMap<in K, MutableList<T>>> Sequence<T>.group
|
||||
*
|
||||
* @sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
*
|
||||
* The operation is _terminal_ and _stateful_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Sequence<T>.groupByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {
|
||||
for (element in this) {
|
||||
@@ -815,7 +815,7 @@ public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R> {
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Sequence<R> {
|
||||
return TransformingIndexedSequence(this, transform)
|
||||
@@ -827,7 +827,7 @@ public fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Seque
|
||||
* @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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T) -> R?): Sequence<R> {
|
||||
return TransformingIndexedSequence(this, transform).filterNotNull()
|
||||
@@ -839,7 +839,7 @@ public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T)
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C {
|
||||
forEachIndexed { index, element -> transform(index, element)?.let { destination.add(it) } }
|
||||
@@ -852,7 +852,7 @@ public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndex
|
||||
* @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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C {
|
||||
var index = 0
|
||||
@@ -875,7 +875,7 @@ public 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapNotNullTo(destination: C, transform: (T) -> R?): C {
|
||||
forEach { element -> transform(element)?.let { destination.add(it) } }
|
||||
@@ -886,7 +886,7 @@ public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapNotNu
|
||||
* 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_.
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destination: C, transform: (T) -> R): C {
|
||||
for (item in this)
|
||||
@@ -897,7 +897,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destinat
|
||||
/**
|
||||
* Returns a sequence of [IndexedValue] for each element of the original sequence.
|
||||
*
|
||||
* The operation is _intermediate_ and _nearly stateless_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.withIndex(): Sequence<IndexedValue<T>> {
|
||||
return IndexingSequence(this)
|
||||
@@ -1333,7 +1333,7 @@ public 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
public operator fun <T> Sequence<T>.minus(element: T): Sequence<T> {
|
||||
return object: Sequence<T> {
|
||||
@@ -1405,7 +1405,7 @@ public 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_.
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Sequence<T>.minusElement(element: T): Sequence<T> {
|
||||
|
||||
@@ -37,7 +37,6 @@ fun filtering(): List<GenericFunction> {
|
||||
templates add f("drop(n: Int)") {
|
||||
val n = "\$n"
|
||||
doc { "Returns a list containing all elements except first [n] elements." }
|
||||
sequenceClassification(nearly_stateless)
|
||||
returns("List<T>")
|
||||
body {
|
||||
"""
|
||||
@@ -108,7 +107,6 @@ fun filtering(): List<GenericFunction> {
|
||||
templates add f("take(n: Int)") {
|
||||
val n = "\$n"
|
||||
doc { "Returns a list containing first [n] elements." }
|
||||
sequenceClassification(nearly_stateless)
|
||||
returns("List<T>")
|
||||
body {
|
||||
"""
|
||||
@@ -769,10 +767,10 @@ fun filtering(): List<GenericFunction> {
|
||||
|
||||
val terminalOperationPattern = Regex("^\\w+To")
|
||||
templates.forEach { with (it) {
|
||||
if (sequenceClassification.isEmpty()) {
|
||||
sequenceClassification(if (signature.contains("index", ignoreCase = true)) nearly_stateless else stateless)
|
||||
}
|
||||
sequenceClassification.add(0, if (terminalOperationPattern in signature) terminal else intermediate)
|
||||
if (terminalOperationPattern in signature)
|
||||
sequenceClassification(terminal)
|
||||
else
|
||||
sequenceClassification(intermediate, stateless)
|
||||
} }
|
||||
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ fun generators(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
doc(Sequences) { "Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element]." }
|
||||
sequenceClassification(intermediate, nearly_stateless)
|
||||
sequenceClassification(intermediate, stateless)
|
||||
|
||||
returns("List<T>")
|
||||
returns("SELF", Sets, Sequences)
|
||||
@@ -308,7 +308,7 @@ fun generators(): List<GenericFunction> {
|
||||
|
||||
|
||||
doc(Sequences) { "Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element]." }
|
||||
sequenceClassification(intermediate, nearly_stateless)
|
||||
sequenceClassification(intermediate, stateless)
|
||||
body(Sequences) {
|
||||
"""
|
||||
return object: Sequence<T> {
|
||||
|
||||
@@ -301,7 +301,7 @@ fun mapping(): List<GenericFunction> {
|
||||
@sample samples.collections.Collections.Transformations.groupBy
|
||||
"""
|
||||
}
|
||||
sequenceClassification(terminal, stateful)
|
||||
sequenceClassification(terminal)
|
||||
typeParam("K")
|
||||
returns("Map<K, List<T>>")
|
||||
body { "return groupByTo(LinkedHashMap<K, MutableList<T>>(), keySelector)" }
|
||||
@@ -323,7 +323,7 @@ fun mapping(): List<GenericFunction> {
|
||||
@sample samples.collections.Collections.Transformations.groupBy
|
||||
"""
|
||||
}
|
||||
sequenceClassification(terminal, stateful)
|
||||
sequenceClassification(terminal)
|
||||
returns("M")
|
||||
body {
|
||||
"""
|
||||
@@ -352,7 +352,7 @@ fun mapping(): List<GenericFunction> {
|
||||
@sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
"""
|
||||
}
|
||||
sequenceClassification(terminal, stateful)
|
||||
sequenceClassification(terminal)
|
||||
typeParam("K")
|
||||
typeParam("V")
|
||||
returns("Map<K, List<V>>")
|
||||
@@ -379,7 +379,7 @@ fun mapping(): List<GenericFunction> {
|
||||
@sample samples.collections.Collections.Transformations.groupByKeysAndValues
|
||||
"""
|
||||
}
|
||||
sequenceClassification(terminal, stateful)
|
||||
sequenceClassification(terminal)
|
||||
returns("M")
|
||||
body {
|
||||
"""
|
||||
@@ -425,8 +425,10 @@ fun mapping(): List<GenericFunction> {
|
||||
val terminalOperationPattern = Regex("^\\w+To")
|
||||
templates.forEach { with (it) {
|
||||
if (sequenceClassification.isEmpty()) {
|
||||
sequenceClassification(if (terminalOperationPattern in signature) terminal else intermediate)
|
||||
sequenceClassification(if (signature.contains("index", ignoreCase = true)) nearly_stateless else stateless)
|
||||
if (terminalOperationPattern in signature)
|
||||
sequenceClassification(terminal)
|
||||
else
|
||||
sequenceClassification(intermediate, stateless)
|
||||
}
|
||||
} }
|
||||
return templates
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package templates
|
||||
|
||||
import templates.Family.*
|
||||
import templates.SequenceClass.intermediate
|
||||
import templates.SequenceClass.stateful
|
||||
import templates.SequenceClass.*
|
||||
|
||||
fun ordering(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
@@ -80,7 +80,6 @@ enum class SequenceClass {
|
||||
terminal,
|
||||
intermediate,
|
||||
stateless,
|
||||
nearly_stateless,
|
||||
stateful
|
||||
}
|
||||
|
||||
@@ -457,7 +456,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
||||
}
|
||||
if (f == Sequences && sequenceClassification.isNotEmpty()) {
|
||||
builder.append(" *\n")
|
||||
builder.append(" * The operation is ${sequenceClassification.joinToString(" and ") { "_${it.toString().replace('_', ' ')}_" }}.\n")
|
||||
builder.append(" * The operation is ${sequenceClassification.joinToString(" and ") { "_${it}_" }}.\n")
|
||||
}
|
||||
builder.append(" */\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user