Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

["Request"] OptionRaise available in Option.catch {} #3461

Open
postfixNotation opened this issue Jun 27, 2024 · 0 comments
Open

["Request"] OptionRaise available in Option.catch {} #3461

postfixNotation opened this issue Jun 27, 2024 · 0 comments

Comments

@postfixNotation
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant