Skip to content

Instantly share code, notes, and snippets.

@purefn
Created September 23, 2012 16:42
Show Gist options
  • Save purefn/3772261 to your computer and use it in GitHub Desktop.
Save purefn/3772261 to your computer and use it in GitHub Desktop.
trait Option[+A] {
@inline final def cata[Z](some: A => Z, none: => Z) = this match {
case Some(a) => some(a)
case None => none
}
}
object Option {
private[Option] case class Some[+A](a: A) extends Option[A]
private[Option] case object None extends Option[Nothing]
def some[A](a: A): Option[A] = Some(a)
def none: Option[Nothing] = None
}
@retronym
Copy link

Option will need to be an abstract class for the inliner to work in 2.9. Not sure if that limitation will be lifted for 2.10.0 or for .1.

@retronym
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment