runningFold
Returns a sequence containing successive accumulation values generated by applying operation from left to right to each element and current accumulator value that starts with initial value.
fun <T, R> Sequence<T>.runningFold(initial: R, operation: (acc: R, T) -> R): Sequence<R>(source)
val numbers = sequenceOf(1, 2, 3, 4)
val cumulativeSums = numbers.runningFold(0) { sum, n -> sum + n }
println(cumulativeSums.toList()) // Output: [0, 1, 3, 6, 10]