https://kotlinlang.org logo
Title
j

julioromano

10/07/2021, 9:31 AM
Is it possible to transform a flow into a flow that emits a rolling window of N elements? As if:
flowOf<Int>(0,1,2,3,4,5,6,7,8,9).magicOperator(2).collect { values: List<Int> ->
 print("${values}; ")
}
Would print:
0,1; 1,2; 2,3; 3,4; 4,5; 5,6; 6,7; 7,8; 8,9
e

ephemient

10/07/2021, 9:34 AM
j

Joffrey

10/07/2021, 10:58 AM
I don't think
chunked
is relevant here, it's more about
windowed
or
zipWithNext
m

myanmarking

10/07/2021, 11:35 AM
you can try to hack a way with scan operator maybe ?
j

julioromano

10/07/2021, 11:37 AM
The proposed implementation of
zipWithNext
did it great! Thanks!
e

ephemient

10/07/2021, 11:39 AM
@Joffrey chunked isn't relevant but comments and PRs there include both chunked and windowed
👌 1