can anyone tell me what is correct way to write Ei...
# arrow
m
can anyone tell me what is correct way to write Either<A,B> ? when i set Exception and when Error in Left Side ? As i want to set result in the Right.
t
you mean something like this?:
Copy code
fun 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:
Copy code
fun foo(bar : Boolean) : Either<Exception, String> {
   return Either.catch {
     if(bar) {
      throw new RuntimeException()
   } else {
      "correct"
   }
}
}
m
Yes. Thank you