stdlib: Add Grouping.eachCount extension

This commit is contained in:
Ilya Matveev
2017-04-17 16:48:37 +07:00
committed by ilmat192
parent c7963a86c1
commit 1c081d351b
@@ -235,6 +235,15 @@ public inline fun <S, T : S, K, M : MutableMap<in K, S>> Grouping<T, K>.reduceTo
if (first) e else operation(key, acc as S, e)
}
/**
* Groups elements from the [Grouping] source by key and counts elements in each group.
*
* @return a [Map] associating the key of each group with the count of elements in the group.
*
* @sample samples.collections.Collections.Transformations.groupingByEachCount
*/
@SinceKotlin("1.1")
public fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> = eachCountTo(mutableMapOf<K, Int>())
/**
* Groups elements from the [Grouping] source by key and counts elements in each group to the given [destination] map.