https://kotlinlang.org logo
Title
n

nitrog42

01/18/2021, 3:44 PM
myFlow.previousMap { previousValue, currentValue -> }
w

wasyl

01/18/2021, 3:46 PM
You’re likely looking for a
scan
or
runningReduce
operator
n

nitrog42

01/18/2021, 3:48 PM
oh i didn't know about runningReduce
but it will replay each emitted value for each new value right ?
I'll do some tests
d

Dominaezzz

01/18/2021, 3:50 PM
zipWithNext?
n

nitrog42

01/18/2021, 3:52 PM
ok runningReduce was exactly what I was looking for, thank you @wasyl
👍 3
c

Casey Brooks

01/18/2021, 4:00 PM
@Dominaezzz that was my first thought, but it doesn’t look like
zipWithNext
is defined for Flow. But the issue requesting it does have a simple implementation of that operator https://github.com/Kotlin/kotlinx.coroutines/issues/1767
👍 1
n

nitrog42

01/18/2021, 4:08 PM
and using flow for byte-by-byte transfer is not ideal either.
I wonder why though
d

Dominaezzz

01/18/2021, 4:09 PM
You could compare it to reading a file into memory, byte by byte, instead of in chunks.
n

nitrog42

01/18/2021, 4:10 PM
yes but what would be better than flow for this use case ? channels ?
d

Dominaezzz

01/18/2021, 4:53 PM
Flow of byte buffers maybe.
r

rook

01/19/2021, 4:10 PM
@nitrog42 Take a look at how Okio works. It’s very elegant and is 100% in Kotlin as of 2018 https://square.github.io/okio/
I believe they also have plans to integrate coroutine usage into the library as well
n

nitrog42

01/19/2021, 4:13 PM
oh i know about okio 😄
I definitelly use it when I can
💯 1