Either Try, and Validation in Scala

I am confused with Either , Try and Validation from scalaz . None of them seem to be doing what I need. I need the simple Result[E, R] monad, where E is the error type and R is the result type.

  • Either not suitable because it is not a monad (but a projection) and impartial.
  • Try not suitable, as its error type is Throwable , and it’s not really a monad
  • Validation not a monad at all.

What would you suggest? Should I write this type of Result myself?

+7
scala monads error-handling scalaz
source share
1 answer

If you want to use Scalaz (and it looks like you), \/ (usually pronounced "disjunction") is exactly what you are looking for - a monadic, right-handed, biased version of Either .

It also includes many other nice things that you don't get with the correct Either projection in the standard library ( 1.right syntax, combinators like +++ , converters from Validation , etc.).

+8
source share

All Articles