Using Either to process failures in Scala code

Either is used to return one of possible two meaningful results, unlike Option which is used to return a single meaningful result or nothing. An easy to understand example is given below (circulated on the Scala mailing list a while back): def throwableToLeft[T](block: => T): Either[java.lang.Throwable, T] = try { Right(block) } catch { case … Read more

Method parameters validation in Scala, with for comprehension and monads

If you’re willing to use Scalaz, it has a handful of tools that make this kind of task more convenient, including a new Validation class and some useful right-biased type class instances for plain old scala.Either. I’ll give an example of each here. Accumulating errors with Validation First for our Scalaz imports (note that we … Read more