https://kotlinlang.org logo
#announcements
Title
# announcements
m

mc

07/05/2019, 1:07 PM
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

Dominaezzz

07/05/2019, 1:10 PM
Yes.
try
and
catch
.
m

mc

07/05/2019, 2:17 PM
No. I said abstraction. Inlining is not abstraction.
3 Views