https://kotlinlang.org logo
#android
Title
# android
y

Yoav Gross

09/26/2019, 12:01 PM
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

gildor

09/26/2019, 12:50 PM
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

Yoav Gross

09/26/2019, 1:35 PM
Thanks @gildor , how do I consume the flow? I can’t use flow collect
g

gildor

09/26/2019, 1:36 PM
Why do you cannot use it?
y

Yoav Gross

09/26/2019, 1:36 PM
It doesn’t compile
g

gildor

09/26/2019, 1:37 PM
And what is error? Have you import collect extension?
y

Yoav Gross

09/26/2019, 1:38 PM
Screen Shot 2019-09-26 at 16.38.27.png
g

gildor

09/26/2019, 1:42 PM
import kotlinx.coroutines.flow.collect
Alt+Enter on error, it will suggest you to import it automatically
y

Yoav Gross

09/26/2019, 1:44 PM
Nice that helped! Studio didn’t mark it for import for some reason, manual import helped. 💯
g

gildor

09/26/2019, 1:45 PM
I see on your screenshot that studio suggests you import (underlined
collect
function means that there is some suitable import)
👍 1
😅 1
3 Views