Created
November 17, 2016 04:40
-
-
Save jeremyrsmith/1e160b335c2cdb39d8ea9acdef5c374d to your computer and use it in GitHub Desktop.
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 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