chunked

fun <T> Flow<T>.chunked(window: Duration, maxSize: Int = Int.MAX_VALUE): Flow<List<T>>

Collects values into lists bounded by a time window and an optional maxSize.

A chunk opens when its first value arrives and is emitted either when window has elapsed since the chunk opened or when it reaches maxSize, whichever happens first. A non-empty chunk in progress is emitted when the upstream completes. Empty lists are never emitted. The upstream is collected without conflation; values wait for the collector when it is slow.

Throws

if window is not positive or maxSize is less than 1.


fun <T> Flow<T>.chunked(size: Int): Flow<List<T>>

Groups values into lists of size elements, emitting the final partial list on completion.

Throws

when size is less than 1.