Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.28 KB | None | 0 0
  1. sealed trait Option[A] {
  2.   def fold[B](ifEmpty: => B)(f: A => B): B = {
  3.     this match {
  4.       case Some(a) => f(a)
  5.       case None  => ifEmpty // ifEmpty is only evaluated here
  6.     }
  7.  
  8.   }
  9. }
  10.  
  11. case class Some[A](a: A) extends Option[A]
  12. case object None extends Option[Nothing]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement