Groups elements from the Grouping source by key and counts elements in each group.
Since Kotlin
1.1Return
a Map associating the key of each group with the count of elements in the group.
Samples
fun main() {
val words = "one two three four five six seven eight nine ten".split(' ')
val frequenciesByFirstChar = words.groupingBy { it.first() }.eachCount()
println("Counting first letters:")
println(frequenciesByFirstChar)
val moreWords = "eleven twelve".split(' ')
val moreFrequencies = moreWords.groupingBy { it.first() }.eachCountTo(frequenciesByFirstChar.toMutableMap())
println(moreFrequencies)
}
Target: JVMRunning on v.2.1.20
Groups elements from the Grouping source by key and counts elements in each group.
Since Kotlin
1.1Return
a Map associating the key of each group with the count of elements in the group.
Samples
fun main() {
val words = "one two three four five six seven eight nine ten".split(' ')
val frequenciesByFirstChar = words.groupingBy { it.first() }.eachCount()
println("Counting first letters:")
println(frequenciesByFirstChar)
val moreWords = "eleven twelve".split(' ')
val moreFrequencies = moreWords.groupingBy { it.first() }.eachCountTo(frequenciesByFirstChar.toMutableMap())
println(moreFrequencies)
}
Target: JVMRunning on v.2.1.20
Groups elements from the Grouping source by key and counts elements in each group.
Since Kotlin
1.3Return
a Map associating the key of each group with the count of elements in the group.
Samples
fun main() {
val words = "one two three four five six seven eight nine ten".split(' ')
val frequenciesByFirstChar = words.groupingBy { it.first() }.eachCount()
println("Counting first letters:")
println(frequenciesByFirstChar)
val moreWords = "eleven twelve".split(' ')
val moreFrequencies = moreWords.groupingBy { it.first() }.eachCountTo(frequenciesByFirstChar.toMutableMap())
println(moreFrequencies)
}
Target: JVMRunning on v.2.1.20