pairwise

fun <T> Flow<T>.pairwise(): Flow<Pair<T, T>>

Emits consecutive pairs of upstream values, starting with the second value.

For upstream a, b, c the output is (a, b), (b, c). Flows with fewer than two values produce nothing.


fun <T, R> Flow<T>.pairwise(transform: suspend (previous: T, current: T) -> R): Flow<R>

Applies transform to each pair of consecutive upstream values.

For upstream a, b, c the output is transform(a, b), transform(b, c). Flows with fewer than two values produce nothing.