Skip to content

Instantly share code, notes, and snippets.

@travisbrown
Created September 16, 2012 15:29
Show Gist options
  • Save travisbrown/3732844 to your computer and use it in GitHub Desktop.
Save travisbrown/3732844 to your computer and use it in GitHub Desktop.
Disjunction monoid example
scala> import scalaz._, Scalaz._
import scalaz._
import Scalaz._
scala> val a: String \/ Int = "x".left
a: scalaz.\/[String,Int] = -\/(x)
scala> val b: String \/ Int = "y".left
b: scalaz.\/[String,Int] = -\/(y)
scala> val c: String \/ Int = 1.right
c: scalaz.\/[String,Int] = \/-(1)
scala> val d: String \/ Int = 2.right
d: scalaz.\/[String,Int] = \/-(2)
scala> a |+| b
res0: scalaz.\/[String,Int] = -\/(xy)
scala> a |+| c
res1: scalaz.\/[String,Int] = -\/(x)
scala> c |+| d
res2: scalaz.\/[String,Int] = \/-(3)
scala> List(a, b, c, d).suml
res3: scalaz.\/[String,Int] = -\/(xy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment