Created
August 25, 2011 03:28
-
-
Save sidharthkuruvila/1169917 to your computer and use it in GitHub Desktop.
Use a for comprehension to extract values from Option objects
This file contains hidden or 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
| 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