Created
June 12, 2013 08:08
-
-
Save gszeliga/5763586 to your computer and use it in GitHub Desktop.
Monads http://scabl.blogspot.com/2013/02/monads-in-scala-1.html
http://scabl.blogspot.com/2013/03/monads-in-scala-2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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