scan
Returns a list containing successive accumulation values generated by applying operation from left to right to each element and current accumulator value that starts with initial value.
inline fun <T, R> Array<out T>.scan(initial: R, operation: (acc: R, T) -> R): List<R>(source)
fun main() {
val numbers = arrayOf(1, 2, 3, 4)
// Compute running totals starting from 0
val runningTotals = numbers.scan(0) { acc, value -> acc + value }
println(runningTotals) // prints [0, 1, 3, 6, 10]
}