Standard Library Utilities
Collection Helpers
Use collection helpers to transform and summarize a short list.
Collection Helpers
CollectionHelpers.kt
fun main() {
val bonus =
val scores = listOf(1, 3, 5)
val adjusted = scores.map { score ->
score + bonus
}
val high = adjusted.filter { score ->
score >= 5
}
val summary = high.joinToString("-")
println("bonus=$bonus")
println("count=${high.size}")
println("summary=$summary")
}
fun main() {
val bonus =
val scores = listOf(1, 3, 5)
val adjusted = scores.map { score ->
score + bonus
}
val high = adjusted.filter { score ->
score >= 5
}
val summary = high.joinToString("-")
println("bonus=$bonus")
println("count=${high.size}")
println("summary=$summary")
}
fun main() {
val bonus =
val scores = listOf(1, 3, 5)
val adjusted = scores.map { score ->
score + bonus
}
val high = adjusted.filter { score ->
score >= 5
}
val summary = high.joinToString("-")
println("bonus=$bonus")
println("count=${high.size}")
println("summary=$summary")
}
collection-helpers
Small helpers such as `map`, `filter`, and `joinToString` make collection steps readable.