fold and reduce
reduce combines items with the first as the start. fold lets you pick a start value.
Example
val n = listOf(1, 2, 3, 4)
println(n.reduce { a, b -> a + b })
println(n.fold(10) { acc, x -> acc + x })
println(n.runningFold(0) { a, b -> a + b })Exercise
Starting value.
list.(0) { a, b -> a + b }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.