Skip to content
Discussion options

You must be logged in to vote

map {} is probably the easiest way to signal your intent here.
For conditionally, you can just use if (2 == 2) 2.right() else RuntimeException().left()
The better way is to use Raise:

context(_: Raise<Throwable>)
fun ex1() { log.info(5) }
context(_: Raise<Throwable>)
fun ex2(): Int = if (2 == 2) 2 else raise(RuntimeException())
// or even

context(_: Raise<Throwable>)
fun ex2(): Int {
  ensure(2 == 2) { RuntimeException() }
  return 2
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kyay10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants