Skip to content

Instantly share code, notes, and snippets.

@sidharthkuruvila
Created August 21, 2011 05:42
Show Gist options
  • Select an option

  • Save sidharthkuruvila/1160196 to your computer and use it in GitHub Desktop.

Select an option

Save sidharthkuruvila/1160196 to your computer and use it in GitHub Desktop.
Wrap method calls that return null in Option
def canReturnNull() = "hello world"
println(Option(canReturnNull) getOrElse "I'm saying nothing")
//Prints: hello world
def canReturnNull() = null
println(Option(canReturnNull) getOrElse "I'm saying nothing")
//Prints: I'm saying nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment