• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

groupBySamplenull1 fun groupBySample() {
2     val words = listOf("a", "abc", "ab", "def", "abcd")
3     val byLength = words.groupBy { it.length }
4 
5     assertPrints(byLength.keys, "[1, 3, 2, 4]")
6     assertPrints(byLength.values, "[[a], [abc, def], [ab], [abcd]]")
7 
8     val mutableByLength: MutableMap<Int, MutableList<String>> = words.groupByTo(mutableMapOf()) { it.length }
9     // same content as in byLength map, but the map is mutable
10     assertTrue(mutableByLength == byLength)
11 }
12 
13 
14 /**
15  * @sample groupBySample
16  */
foonull17 fun foo() {
18 
19 }