https://kotlinlang.org logo
Title
r

Robert Jaros

04/15/2019, 6:59 PM
I've read all about `Flow`s and I still do not understand if/how I can replace channels with flows in my library. I really need to be able to do
.send
on the one side and iterate when reading on the other side, but at the same time I need to transform the data using
map
and
filter
, which are obsolete for channels.
d

Dominaezzz

04/15/2019, 7:12 PM
Flows are not a replacement for channels
They are simply a way to expose cold streams.
In your case your can use a Channel still for sending but pass around a Flow for receiving.
o

octylFractal

04/15/2019, 7:13 PM
additionally, you can create your own flow by simply doing https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html its a little more restricted than a channel, since it's a cold stream -- coroutine does not run until first request
d

Dominaezzz

04/15/2019, 7:15 PM
Channel<>.asFlow()
should help.
r

Robert Jaros

04/15/2019, 9:01 PM
Where is
asFlow
defined?