You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -30,21 +47,36 @@ right before the operation execution.
30
47
31
48
Namely, `Grouping` supports the following operations:
32
49
33
-
*[`eachCount()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/each-count.html) counts the elements in each group.
50
+
*[`eachCount()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/each-count.html) counts the elements in each group.
34
51
*[`fold()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/fold.html) and [`reduce()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reduce.html)
35
-
perform [fold and reduce](collection-aggregate.md#fold-and-reduce) operations on each group as a separate collection
36
-
and return the results.
52
+
perform [fold and reduce](collection-aggregate.md#fold-and-reduce) operations on each group as a separate collection
53
+
and return the results.
37
54
*[`aggregate()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/aggregate.html) applies a given operation
38
-
subsequently to all the elements in each group and returns the result.
39
-
This is the generic way to perform any operations on a `Grouping`. Use it to implement custom operations when fold or reduce are not enough.
55
+
subsequently to all the elements in each group and returns the result.
56
+
This is the generic way to perform any operations on a `Grouping`. Use it to implement custom operations when fold or reduce are not enough.
40
57
41
-
```kotlin
58
+
You can use the `for` operator on the resulting `Map` to iterate through the groups created by the `groupingBy()` function.
59
+
This allows you to access each key and the count of elements associated with that key.
60
+
61
+
The following example demonstrates how to group strings by their first letter using the `groupingBy()` function,
62
+
count the elements in each group, and then iterate through each group to print the key and count of elements:
42
63
64
+
```kotlin
43
65
funmain() {
44
66
//sampleStart
45
-
val numbers =listOf("one", "two", "three", "four", "five", "six")
0 commit comments