```public fun <T> Flow<T>.onEmpty(acti...
# coroutines
m
Copy code
public fun <T> Flow<T>.onEmpty(action: suspend FlowCollector<T>.() -> Unit): Flow<T> {
    var valueCount: Int = 0
    return flow {
        collect { valueCount += 1; emit(it) }
        if(valueCount == 0) action()
    }
}
does this makes sense in terms of implementation ?
👍 1
e
Looks good to me
m
will this work: flowOf<Int>().onEmpty{ emit(0) }. From my test it works, but someone mentioned it wont
e
It should work.