with Default
fun <T> ERROR CLASS: Symbol not found for Flow<T>.withDefault(default: T): ERROR CLASS: Symbol not found for Flow<T>(source)
Emits the provided default value if the upstream flow is empty.
Example:
val emptyFlow = emptyFlow<Int>()
emptyFlow.withDefault(0).collect { println(it) }Content copied to clipboard
Result is 0.
fun <T> ERROR CLASS: Symbol not found for Flow<T>.withDefault(default: T, shouldDefault: (Throwable) -> Boolean): ERROR CLASS: Symbol not found for Flow<T>(source)
Emits the provided default value if the upstream flow is empty and .
CancellationException is always rethrown.
Example:
val failingFlow = flow {
emit(1)
throw ArithmeticException()
emit(2)
}
failingFlow.withDefault(0) { it is ArithmeticException }.collect { println(it) }Content copied to clipboard
Result is 1, 0
Parameters
default
the value to emit if no value is emitted.
should Default
returns default when true