3 ms·
Sure, if you're willing to create a sealed trait, and separate exception classes, for every function that wants to do this. What this really needs to be usable
by azernik 11y ago
Sure, if you're willing to create a sealed trait, and separate exception classes, for every function that wants to do this.
What this really needs to be usable is union (sum) types
So in this case:
def dangerousFunction(): Either[FileNotFoundError | JsonParseError, Int] = {
???
}
...and looking for this online, it turns out this is a feature in the experimental Dotty compiler. Yay.
And yeah, right-biased either would get halfway there. But it's really the terminology and naming that I have an issue. If I could get an Either knockoff that just called its left and right "error" and "success", that would go a long way to readability.