[edit]

Disjunction GitHub

Disjunction (or \/) is a data type used to signal multiple possible outcomes of a computation. It is often used when dealing with errors, but is not tied to that case.

Typical imports

import scalaz._
import Scalaz._

Construction

scala> val l: String \/ Int = "foo".left
l: String \/ Int = -\/(foo)

scala> val r: Long \/ Int = 42.right
r: Long \/ Int = \/-(42)

Pattern matching

scala> l match {
     |   case -\/(left) => println(left)
     |   case \/-(right) => println(right)
     | }
foo

Use the Monad instance

scala> r.flatMap { right =>
     |   \/-(right)
     | }
res1: Long \/ Int = \/-(42)
ore