runningFold
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>.runningFold(initial: R, operation: (acc: R, T) -> R): List<R>(source)
val numbers = arrayOf(1, 2, 3, 4)
val cumulativeSums = numbers.runningFold(0) { acc, value -> acc + value }
println(cumulativeSums) // [0, 1, 3, 6, 10]