Skip to content
Justice Tech School

groupBy, associate and partition

groupBy buckets items, associateBy builds a map and partition splits in two.

Example
val w = listOf("apple", "avocado", "banana")
println(w.groupBy { it.first() })
println(w.associateBy { it.length })
val (short, long) = w.partition { it.length < 6 }
println("$short $long")

Exercise

Split in two.

list. { it > 1 }

Quiz Test

What does partition return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.