Rename Grouping.elementIterator to sourceIterator
This commit is contained in:
@@ -7720,7 +7720,7 @@ public inline fun <K, V, M : MutableMap<in K, MutableList<V>>> CharArray.groupBy
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <T, K> Array<out T>.groupingBy(crossinline keySelector: (T) -> K): Grouping<T, K> {
|
||||
return object : Grouping<T, K> {
|
||||
override fun elementIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun sourceIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun keyOf(element: T): K = keySelector(element)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1197,7 +1197,7 @@ public inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Iterable<T>.gr
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <T, K> Iterable<T>.groupingBy(crossinline keySelector: (T) -> K): Grouping<T, K> {
|
||||
return object : Grouping<T, K> {
|
||||
override fun elementIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun sourceIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun keyOf(element: T): K = keySelector(element)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,7 +670,7 @@ public inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Sequence<T>.gr
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <T, K> Sequence<T>.groupingBy(crossinline keySelector: (T) -> K): Grouping<T, K> {
|
||||
return object : Grouping<T, K> {
|
||||
override fun elementIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun sourceIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun keyOf(element: T): K = keySelector(element)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,7 +717,7 @@ public inline fun <K, V, M : MutableMap<in K, MutableList<V>>> CharSequence.grou
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <K> CharSequence.groupingBy(crossinline keySelector: (Char) -> K): Grouping<Char, K> {
|
||||
return object : Grouping<Char, K> {
|
||||
override fun elementIterator(): Iterator<Char> = this@groupingBy.iterator()
|
||||
override fun sourceIterator(): Iterator<Char> = this@groupingBy.iterator()
|
||||
override fun keyOf(element: Char): K = keySelector(element)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ package kotlin.collections
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public interface Grouping<T, out K> {
|
||||
/** Returns an [Iterator] which iterates through the elements of the source. */
|
||||
fun elementIterator(): Iterator<T>
|
||||
/** Returns an [Iterator] over the elements of the source of this grouping. */
|
||||
fun sourceIterator(): Iterator<T>
|
||||
/** Extracts the key of an [element]. */
|
||||
fun keyOf(element: T): K
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public inline fun <T, K, R, M : MutableMap<in K, R>> Grouping<T, K>.aggregateTo(
|
||||
destination: M,
|
||||
operation: (key: K, accumulator: R?, element: T, first: Boolean) -> R
|
||||
): M {
|
||||
for (e in this.elementIterator()) {
|
||||
for (e in this.sourceIterator()) {
|
||||
val key = keyOf(e)
|
||||
val accumulator = destination[key]
|
||||
destination[key] = operation(key, accumulator, e, accumulator == null && !destination.containsKey(key))
|
||||
|
||||
Reference in New Issue
Block a user