Skip to content

Instantly share code, notes, and snippets.

@sidharthkuruvila
Created August 25, 2011 03:28
Show Gist options
  • Select an option

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

Select an option

Save sidharthkuruvila/1169917 to your computer and use it in GitHub Desktop.
Use a for comprehension to extract values from Option objects
val hello = Some("Hello")
val world = Some("World")
println(for(a <- hello; b <- world) yield a + b)
//prints: Some(HelloWorld)
val none = None
println(for(a <- hello; b <-None) yield a + b)
//prints: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment