Skip to content

Instantly share code, notes, and snippets.

@daithiocrualaoich
Created January 3, 2012 15:10
Show Gist options
  • Save daithiocrualaoich/1555284 to your computer and use it in GitHub Desktop.
Save daithiocrualaoich/1555284 to your computer and use it in GitHub Desktop.
.option on nullable types
implicit def nullable2Option[N >: Null](n: N) = new {
lazy val option: Option[N] = Option(n)
}
val s1: String = "1234"
s1.option // Option[String] = Some(1234)
val s2: String = null
s2.option // Option[String] = None
null.option // ERROR: Alas...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment