Kotlin Collection Functions
map, filter, reduce, sum, any, all, groupBy and sortedBy transform collections in a functional style with lambdas.
Example
val n = listOf(1, 2, 3, 4, 5, 6)
println(n.map { it * 2 })
println(n.filter { it % 2 == 0 })
println(n.sum())
println(n.groupBy { it % 3 })Exercise
Keep matching items.
n. { it > 2 }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.