runningReduceIndexed
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 the first element of this sequence.
fun <S, T : S> Sequence<T>.runningReduceIndexed(operation: (index: Int, acc: S, T) -> S): Sequence<S>(source)
fun main() {
val seq = sequenceOf(10, 20, 30, 40)
val result = seq.runningReduceIndexed { index, acc, elem ->
acc + elem + index // sum element and its index to the accumulator
}.toList()
println(result) // prints: [10, 31, 64, 109]
}