Skip to content

Commit

Permalink
Update task.md
Browse files Browse the repository at this point in the history
language checked
  • Loading branch information
stephen-hero authored Nov 7, 2023
1 parent 897b78a commit 5025605
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions oldSchoolServer/oldSchoolServerGroupBy/task.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
In Kotlin, you can work with collections in a different way.
You can perform not only basic operations like sorting or finding some elements,
You can perform not only basic operations, like sorting or finding some elements,
but also more complex ones.
One such operation is _grouping_ items by a condition.

The easiest way to group elements is to use the built-in [`groupBy`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/group-by.html) function.

This function allows you to group elements of the original collection by the
key returned by the given `keySelector` function applied to each
key returned by the given `keySelector` function, which is applied to each
element and returns a map where each group key is associated with a list of corresponding elements.

In simple words, if you group objects, for example, by their length,
then the keys in the resulting map will be the possible length
values found in the original collection, and for each such key a
list of objects from the original collection of a given length will be compiled.
values found in the original collection, and for each such key, a
list of objects from the original collection with a given length will be compiled.

Consider an example:
```kotlin
Expand All @@ -25,7 +25,7 @@ fun main() {
}
```

This code will print into the console the following output since we group the strings from the list by their length:
Since we group the strings from the list by their length, this code will print into the console the following output:
```text
Current length is 1. The words: a
Current length is 3. The words: abc, def
Expand Down

0 comments on commit 5025605

Please sign in to comment.