So usually, when we run a method that may fail and returns a value, we can encode our return type of the method as Either[SomeErrorType, ReturnType] . But many times we run the method for its side effects, so the return type is Unit .
I could, of course, return Either[SomeErrorType, Unit] , but it definitely looks weird.
I could just return Option[SomeErrorType] , but actually it does not look much better (and breaks, perhaps, the existing symmetry with other Either[SomeErrorType, NonUnitReturnType] s.
What is your approach in these cases?
def m(): Unit // and implicitly know that exceptions can be thrown? ;def m(): Either[SomeErrorType, Unit] // this is odd ;def m(): Option[SomeErrorType] // this is odd, as it makes it look as the return type of t () on a successful run is an error code.- Another thing I can't think of?
thanks
scala
devoured elysium
source share