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

Taha

09/19/2019, 3:11 PM
Hello guys I have a question regarding the flatmap for kotlin and rxjava2. I have an observable of a data class that has a nested list
Copy code
fun getCenterServiceCategories() : Single<CenterServiceCategories>
// ..
data class CenterServiceCategories(
    val meta: MetaResponse,
    val data: List<ServiceCategory>
)
what I want to do The ServiceCategory also has a list of ids that I want to loop through and eventually return a flatmap that has the list of categories with their services embedded. The problem is that I cannot call
Copy code
getCenterServiceCategories().flatmap{ 
//...
}
since the list is actually the data property. i have tried subscribing and getting the data onSubscribe and using Kotlins map and flatmap, but I want to do that with RX any suggestions?
l

Luca Nicoletti

09/19/2019, 3:15 PM
Why can’t you do that? inside the
flatmap{}
you can cycle though the list and do whatever you want
☝️ 1
t

Taha

09/19/2019, 3:20 PM
Hey Luca, the list I need to loop through is CenterServiceCategories>data
l

Luca Nicoletti

09/19/2019, 3:20 PM
Yep exactly, inside the
flatmap{}
you can do
it.data.forEach{}
and cycle through the list
2 Views