I'm often using Option.catch {} but I also need the option {} computation block to have access to OptionRaise. Couldn't the lambda of the former be an OptionRaise receiver to get rid of flatten and one level of indentation?
context(OptionRaise)
fun <T> dataOrThrow(): Option<T> {
...
}
This is how I have to do it now:
fun <T> foo() {
val dataOption: Option<T> = Option.catch {
option {
dataOrThrow()
}
}.flatten()
}
And this is how I want it to be:
fun <T> foo() {
val dataOption: Option<T> = Option.catch {
dataOrThrow()
}
}
So basically I need an option computation block which catches thrown exceptions and translates them as None.
I'm often using
Option.catch {}
but I also need theoption {}
computation block to have access toOptionRaise
. Couldn't the lambda of the former be anOptionRaise
receiver to get rid offlatten
and one level of indentation?This is how I have to do it now:
And this is how I want it to be:
So basically I need an
option
computation block which catches thrown exceptions and translates them asNone
.