Is there a better way to accomplish the following ...
# announcements
m
Is there a better way to accomplish the following (either through abstraction or existing stdlib functions)?
Copy code
fun <R> (suspend () -> R).fallbackTo(block: () -> R) : suspend () -> R = {
    try {
        this()
    } catch (e: Exception) {
        block()
    }
}


fun <T1, R> (suspend (T1) -> R).fallbackTo(block: (T1) -> R) : suspend (T1) -> R = { t1 ->
    try {
        this(t1)
    } catch (e: Exception) {
        block(t1)
    }
}

fun <T1, T2, R> (suspend (T1, T2) -> R).fallbackTo(block: (T1, T2) -> R) : suspend (T1, T2) -> R = { t1, t2 ->
    try {
        this(t1, t2)
    } catch (e: Exception) {
        block(t1, t2)
    }
}
d
Yes.
try
and
catch
.
m
No. I said abstraction. Inlining is not abstraction.