carbaj0
09/03/2022, 6:24 AMcarbaj0
09/03/2022, 6:27 AMfun <A, B> launchIOSafe(
f: suspend () -> Either<A, B>,
error: suspend (A) -> Unit = {},
success: suspend (B) -> Unit = {},
): Job =
launchMain {
IO { f() }.fold(error, success)
}
simon.vergauwen
09/03/2022, 7:59 AMlaunchIOSafe(error = { _: A -> })
. You can never call it with the trailing lambda syntax.
In some cases you can avoid this, but not always. I think in this case this result in any nicer APIs. In fact, it may be even conflicting. Sometimes you can define APIs that are valid in their definition, but ambiguous on the call-site.
fun <A, B> launchIOSafe(
f: suspend () -> Either<A, B>,
error: suspend (A) -> Unit = {},
success: suspend (B) -> Unit
): Job =
launchMain {
IO { f() }.fold(error, success)
}
fun <A, B> launchIOSafe(
f: suspend () -> Either<A, B>,
error: suspend (A) -> Unit
): Job =
launchIOSafe(f, error) { }