Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created January 19, 2013 02:52
Show Gist options
  • Save tonymorris/4570450 to your computer and use it in GitHub Desktop.
Save tonymorris/4570450 to your computer and use it in GitHub Desktop.
object PdxleifMonoid {
trait Monoid[A] {
def op(a1: A, a2: A): A
def id: A
}
def XorMonoid[A]: Monoid[Option[A]] =
new Monoid[Option[A]] {
def op(a1: Option[A], a2: Option[A]) =
(a1, a2) match {
case (None, None) =>
None
case (Some(_), Some(_)) =>
None
case (Some(a), None) =>
Some(a)
case (None, Some(a)) =>
Some(a)
}
def id =
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment