Question

I am confused with Either, Try, and Validation of scalaz. None of them seems to do what I need. What I need is a simple monad Result[E, R] where E is an error type and R is an result type.

  • Either is not suitable because it is not a monad (but the projections are) and unbiased.
  • Try is not suitable since its error type is Throwable and it is not exactly a monad
  • Validation is not a monad at all.

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

Was it helpful?

Solution

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top