Is there a way to compare changes between emission...
# coroutines
d
Is there a way to compare changes between emissions? Example:
Copy code
flowOf(1,2,5)
  .operation { last, current -> current - last }
  .onEach { println(it) }
  .collect()
Result: 1,3
b
it's possible via scan (use Pair<Int, Int> as an accumulator), but easier to write your own zipWithNext function, it's pretty simple
d
Thank you
l
What about .reduce() or fold()? With those you also have access to the previous and the current value.
e
fold is similar to scan, so you need to provide an initial value. reduce throws if the flow was empty. those might work for Dragos, depends on the situation though
d
I want to emit these values further, i think I can put them in a list of lists and then send them further