Greg Hibberd
08/27/2021, 2:20 PMfun getDefault(): Any {
check(false) { "failed"}
TODO()
}
fun method(param: Any = getDefault()) = flow<Any> {
TODO()
}
i.e avoiding loads of these when you have 2+ default values:
fun method() = flow {
method(getDefault())
.collect {
emit(it)
}
}
CLOVIS
08/27/2021, 4:46 PM@JvmOverloads
?Greg Hibberd
08/27/2021, 5:06 PMmethod()
it will throw an exception the regular java way, where ideally you want exceptions to be handled within the async flow. To get the appropriate functionality I have to wrap the default value calls in another flow and create a function for every variation of parameters - what would normally be done automatically by @JvmOverloads
I'm just looking for alternatives so you wouldn't have to wrap the call in two catch statements
launch {
try {
method()
.catch { it.printStackTrace() }
.collect()
} catch (e: Exception) {
e.printStackTrace()
}
}
CLOVIS
08/27/2021, 9:01 PMfun foo(optionalParam: Bar? = null) = flow {
val param = optionalParam ?: getDefault()
emit(...)
}