Dominaezzz
01/31/2021, 5:03 PM@ExperimentalCoroutinesApi
internal fun <T> Flow<T?>.coalesce(other: Flow<T>): Flow<T> {
return distinctUntilChanged { old, new -> old == null && new == null }
.transformLatest {
if (it != null) {
// TODO: Will "Latest" wrongly cancel this branch?
emit(it)
} else {
emitAll(other)
}
}
}
ephemient
01/31/2021, 8:05 PM.flatMapLatest {
flowOf(it ?: return@flatMapLatest other)
}
but it's functionally the same