Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed trait Option[A] {
- def fold[B](ifEmpty: => B)(f: A => B): B = {
- this match {
- case Some(a) => f(a)
- case None => ifEmpty // ifEmpty is only evaluated here
- }
- }
- }
- case class Some[A](a: A) extends Option[A]
- case object None extends Option[Nothing]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement