runningReduce

fun <T> Flow<T>.runningReduce(operation: suspend (accumulator: T, value: T) -> T): Flow<T>(source)

Reduces the given flow with operation, emitting every intermediate result, including initial value. The first element is taken as initial value for operation accumulator. This operator has a sibling with initial value -- scan.

For example:

flowOf(1, 2, 3, 4).runningReduce { acc, value -> acc + value }.toList()

will produce [1, 3, 6, 10]