Hi, does anyone have had success converting from R...
# android
y
Hi, does anyone have had success converting from Rx2 Observable to Kotlin Flow, and getting data?
This code works in the sense that I can the initial data from the channel, but the observable is dead - it doesn’t send anymore data beyond the initial list.
Now how do I extract the List<> from the flow? collect{} doesn’t compile. Furthermore how do I keep this as a stream of data like Rx2?
g
Do not use channel for that, instead convert observable to Flowable and use asFlow()
Because channels are eager, they subscribe immediately
For now there is no adapter for Observable, only for Flowable
✔️ 1
y
Thanks @gildor , how do I consume the flow? I can’t use flow collect
g
Why do you cannot use it?
y
It doesn’t compile
g
And what is error? Have you import collect extension?
y
Screen Shot 2019-09-26 at 16.38.27.png
g
import kotlinx.coroutines.flow.collect
Alt+Enter on error, it will suggest you to import it automatically
y
Nice that helped! Studio didn’t mark it for import for some reason, manual import helped. 💯
g
I see on your screenshot that studio suggests you import (underlined
collect
function means that there is some suitable import)
👍 1
😅 1