dnowak
06/15/2021, 2:27 PM@JvmStatic
@JvmName("tryCatch")
inline fun <A> catch(recover: (Throwable) -> Unit, f: () -> A): Option<A> =
try {
Some(f())
} catch (t: Throwable) {
recover(t.nonFatalOrThrow())
None
}
Why recover is (Throwable) -> Unit not (Throwable) -> Option<A>? Shouldn’t the caller decide if the exception should be mapped to None or Some?timrijckaert
06/15/2021, 3:22 PMEither.catch { }dnowak
06/16/2021, 7:59 AMEither it is a different case -> I can use handleErrorWith to transform Exception to right or left. With Option I have no such ability. That’s why I think that recover for Option should not only allow a side effect.