Closed
Description
It would be useful to have an optional transformation in Flow.buffer
method to aggregate the buffered items like in kotlin.sequences.Sequence.chunked
.
I mean,
fun buffer(capacity: Int = BUFFERED, suspend transform: (List<T>) -> R) : Flow<T>
Then we can write
runBlocking {
(1..100).asFlow().buffer(capacity = 10) { it.sum() }.collect { println(it) }
}
with result 55, 155, 255, ... , 955