Accumulates value starting with the first element and applying operation from left to right.
Syntax
collection.reduce { acc, e -> }Example
Enter values below to update the example in real time.
val→nums→listOf→reduce→acc→println→val nums = listOf(1, 2, 3, 4, 5)
val sum = nums.reduce { acc, n -> acc + n }
println(sum) // 15