alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

How to combine two data-flows in Android app architecture ?

How to combine two data-flows in Android app architecture ?

I've come up with the following implementation:

 pagedUsersFlow.flatMapLatest {
     flow {
         it.map { user ->
             userRemoteDS.getUserStatusFlow(user.id).onEach { status ->
                 emit(UserUI(user, status))
             }.launchIn(coroutineScope)
         }
     }
}.collect { userUI ->
    // use userUI
} 

Update:

 pagedUsersFlow.map {
    it.map { user ->
        val status = userRemoteDS.getUserStatusFlow(user.id).firstOrNull() ?: UserStatus("offline")
        UserUI(user, status)
    }
}.collect { pagingUI: PagingData<UserUI> ->
    // ...
}

41 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online