ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Kotlin Tutorial• 6 min read

Collections & Functional Transformations

listOf, map, filter, flatMap, reduce, and groupBy

Kotlin distinguishes between immutable read-only collections (List, Set, Map) and mutable collections (MutableList, MutableMap), pairing them with powerful functional pipeline operations.

Functional Pipeline Processing

listOf(...): Creates a read-only list with no .add() or .remove() methods.

mutableListOf(...): Creates an editable list.

Higher-Order collection methods: .map { ... }, .filter { ... }, .groupBy { ... }, .sortedByDescending { ... }.

Functional Data Pipeline in Kotlin
val scores = listOf(85, 42, 98, 61, 74, 95)

// Filter passing grades (>= 60), add 5 point curve, sort descending
val honorRoll = scores
    .filter { it >= 60 }
    .map { it + 5 }
    .sortedDescending()

println("Honor Roll: $honorRoll") // [103, 100, 90, 79, 66]
The implicit it parameter refers to the current element in single-parameter lambdas.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

In a single-parameter Kotlin lambda expression, what is the default implicit name of that parameter?