I've read all about `Flow`s and I still do not und...
# coroutines
r
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
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
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
Channel<>.asFlow()
should help.
r
Where is
asFlow
defined?