Skip to content

Instantly share code, notes, and snippets.

@gszeliga
Created June 12, 2013 08:08
Show Gist options
  • Save gszeliga/5763586 to your computer and use it in GitHub Desktop.
Save gszeliga/5763586 to your computer and use it in GitHub Desktop.
sealed trait Maybe[+A] {
// >>=
def flatMap[B](f: A => Maybe[B]): Maybe[B]
}
case class Just[+A](a: A) extends Maybe[A] {
override def flatMap[B](f: A => Maybe[B]) = f(a)
}
// Nothing in the Haskel example
case object MaybeNot extends Maybe[Nothing] {
override def flatMap[B](f: Nothing => Maybe[B]) = MaybeNot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment