runningFoldIndexed

Returns a sequence containing successive accumulation values generated by applying operation from left to right to each element, its index in the original sequence and current accumulator value that starts with initial value.

fun <T, R> Sequence<T>.runningFoldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): Sequence<R>(source)
val numbers = sequenceOf(10, 20, 30)

val result = numbers.runningFoldIndexed(0) { index, acc, value ->
    // add the current value and its index to the accumulator
    acc + value + index
}.toList()

println(result)   // prints: [0, 10, 31, 63]

Source