How do I do the following with LiveData ```privat...
# coroutines
c
How do I do the following with LiveData
Copy code
private val searchString = MutableStateFlow("")
val rooms = searchString.flatMapLatest {
        if (it.isBlank()) {
            fetchPrivateRooms()
        } else {
            fetchPrivateRooms().combineTransform(fetchPublicRooms()) { priv, pub ->
                emit(filterRooms(priv, pub, it))
            }
        }
    }.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
Q: How do I do this if
fetchPrivateRooms
returns a
LiveData<List<Rooms>>
instead of a flow? I can't use observeAsState directly as I wish to merge and transform the data coming from the data source What is my usecase? I wish to use a library that uses livedata extensively in Compose. I've previously use the above code when I was working with
flow
But don't know how to merge and transform livedata within a viewmodel. Note: This business logic is to be seperated from the UI logic and so I can't use a lifecycleowner (I think)
1
n
fetchPublicRooms().asFlow()