Hold back eachSumOf for a while.
This commit is contained in:
@@ -24,6 +24,7 @@ package kotlin.collections
|
|||||||
public fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> =
|
public fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> =
|
||||||
fold(0) { acc, e -> acc + 1 }
|
fold(0) { acc, e -> acc + 1 }
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
/**
|
||||||
* Groups elements from the [Grouping] source by key and sums values provided by the [valueSelector] function for elements in each group.
|
* Groups elements from the [Grouping] source by key and sums values provided by the [valueSelector] function for elements in each group.
|
||||||
*
|
*
|
||||||
@@ -32,3 +33,4 @@ public fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> =
|
|||||||
@SinceKotlin("1.1")
|
@SinceKotlin("1.1")
|
||||||
public inline fun <T, K> Grouping<T, K>.eachSumOf(valueSelector: (T) -> Int): Map<K, Int> =
|
public inline fun <T, K> Grouping<T, K>.eachSumOf(valueSelector: (T) -> Int): Map<K, Int> =
|
||||||
fold(0) { acc, e -> acc + valueSelector(e) }
|
fold(0) { acc, e -> acc + valueSelector(e) }
|
||||||
|
*/
|
||||||
@@ -246,6 +246,7 @@ public fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> =
|
|||||||
public fun <T, K, M : MutableMap<in K, Int>> Grouping<T, K>.eachCountTo(destination: M): M =
|
public fun <T, K, M : MutableMap<in K, Int>> Grouping<T, K>.eachCountTo(destination: M): M =
|
||||||
foldTo(destination, 0) { acc, _ -> acc + 1 }
|
foldTo(destination, 0) { acc, _ -> acc + 1 }
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
/**
|
||||||
* Groups elements from the [Grouping] source by key and sums values provided by the [valueSelector] function for elements in each group.
|
* Groups elements from the [Grouping] source by key and sums values provided by the [valueSelector] function for elements in each group.
|
||||||
*
|
*
|
||||||
@@ -273,7 +274,7 @@ public inline fun <T, K> Grouping<T, K>.eachSumOf(valueSelector: (T) -> Int): Ma
|
|||||||
@SinceKotlin("1.1")
|
@SinceKotlin("1.1")
|
||||||
public inline fun <T, K, M : MutableMap<in K, Int>> Grouping<T, K>.eachSumOfTo(destination: M, valueSelector: (T) -> Int): M =
|
public inline fun <T, K, M : MutableMap<in K, Int>> Grouping<T, K>.eachSumOfTo(destination: M, valueSelector: (T) -> Int): M =
|
||||||
foldTo(destination, 0) { acc, e -> acc + valueSelector(e)}
|
foldTo(destination, 0) { acc, e -> acc + valueSelector(e)}
|
||||||
|
*/
|
||||||
|
|
||||||
@JvmVersion
|
@JvmVersion
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class GroupingTest {
|
|||||||
assertEquals(mapOf('f' to 2, 'b' to 3, 'a' to 1, 'z' to 2), counts2)
|
assertEquals(mapOf('f' to 2, 'b' to 3, 'a' to 1, 'z' to 2), counts2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
@Test fun sumEach() {
|
@Test fun sumEach() {
|
||||||
val values = listOf("k" to 50, "b" to 20, "k" to 1000 )
|
val values = listOf("k" to 50, "b" to 20, "k" to 1000 )
|
||||||
val summary = values.groupingBy { it.first }.eachSumOf { it.second }
|
val summary = values.groupingBy { it.first }.eachSumOf { it.second }
|
||||||
@@ -110,4 +110,5 @@ class GroupingTest {
|
|||||||
|
|
||||||
assertEquals(mapOf("k" to 1053, "b" to 31, "a" to 5), summary2)
|
assertEquals(mapOf("k" to 1053, "b" to 31, "a" to 5), summary2)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user