Skip to content

Instantly share code, notes, and snippets.

@jeremyrsmith
Created November 17, 2016 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyrsmith/1e160b335c2cdb39d8ea9acdef5c374d to your computer and use it in GitHub Desktop.
Save jeremyrsmith/1e160b335c2cdb39d8ea9acdef5c374d to your computer and use it in GitHub Desktop.
sealed trait Option[+T]
case object None extends Option[Nothing]
case class Some[@specialized +T](value: T) extends Option[T]
object Option {
implicit class Ops[A](val opt: Option[A]) extends AnyVal {
@inline final def get(): A = opt match {
case Some(x) => x
case None => throw new NoSuchElementException("None.get")
}
@inline final def getOrElse[B >: A] (default: => B): B = opt match {
case Some(x) => x
case None => default
}
//etc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment