Created
September 20, 2012 05:13
-
-
Save stephenLee/3754082 to your computer and use it in GitHub Desktop.
Scala Option example
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
val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo") | |
capitals get "France" | |
capitals get "North Pole" | |
def show(x: Option[String]) = x match { | |
case Some(x) => x | |
case None => "?" | |
} | |
show(capitals get "Japan") | |
show(capitals get "France") | |
show(capitals get "North Pole") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment