runningReduceIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original array and current accumulator value that starts with the first element of this array.
inline fun <S, T : S> Array<out T>.runningReduceIndexed(operation: (index: Int, acc: S, T) -> S): List<S>(source)
fun main() {
val numbers = arrayOf(10, 20, 30, 40)
val cumulative = numbers.runningReduceIndexed { index, acc, value ->
acc + value + index // add the element and its index to the running total
}
println(cumulative) // [10, 31, 64, 109]
}