Mazhar Ibna Zahur
02/28/2023, 7:08 AMTies
02/28/2023, 8:03 AMfun foo(bar : Boolean) : Either<Exception, String> {
return if(bar) {
Either.left(new RuntimeException())
} else {
Either.right("correct")
}
}
It is also possible to do it "automatically" for exceptions:
fun foo(bar : Boolean) : Either<Exception, String> {
return Either.catch {
if(bar) {
throw new RuntimeException()
} else {
"correct"
}
}
}
Mazhar Ibna Zahur
02/28/2023, 8:05 AM