It is /infuriating/ to be knee-deep trying to work out which of your 30 Eithers failed with a non-descript error.
It is /infuriating/ to be knee-deep trying to work out which of your 30 Eithers failed with a non-descript error.
The Monad instance for Either means that chaining them together with flatMap has a short-circuiting effect and the first failure will stop the rest of the chain from being evaluated. I find this actually makes it easier to know where your errors are happening, and also allows you to centralise your error handling logic.
Compared to Haskell, it is probably better in some way because you have the proper stacktrace; but it “feels” impure a bit.. In a way Java’s exceptions are already an Either type with the result type and the thrown Exception (with “auto-decomposition”, unless checked exceptions) —- is the advantages like manual management of when mapping/flatmapping happens worth it in your opinion? Nonetheless thanks for the heads up, I might try out Scala again with the exception handling model you mentioned!
If you go onto the scaladoc for Either today, you see a stringly-typed Either where they discard the Exception.