eachCount

Groups elements from the Grouping source by key and counts elements in each group.

expect fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int>(source)
fun main() {
    val fruits = listOf("apple", "apricot", "banana", "blueberry", "avocado")
    val countByFirstLetter = fruits.groupingBy { it.first() }.eachCount()
    println(countByFirstLetter) // Output: {a=3, b=2}
}

Source