Last active
December 18, 2015 15:09
-
-
Save sdanzig/5802364 to your computer and use it in GitHub Desktop.
Demonstration of handling Options retrieved from a Map[String, String] ... More details at: http://sdanzig.blogspot.com/2013/06/the-option-design-pattern.html
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
| def firstToLastNameMap : Map[String,String] = Map( | |
| "beth"->"peterson", | |
| "harry"->"smith", | |
| "john"->"doe" | |
| ) | |
| def retrieveLastNameFromMap(firstName: String) = { | |
| firstToLastNameMap.get(firstName) | |
| } | |
| // Sample usage | |
| Console.println("\nRetrieving last name of harry...") | |
| talkAboutValue(retrieveLastNameFromMap("harry")) | |
| Console.println("\nRetrieving last name of ben...") | |
| talkAboutValue(retrieveLastNameFromMap("ben")) | |
| /* Output | |
| Retrieving last name of harry... | |
| value is the String "smith", length of 5 | |
| Retrieving last name of ben... | |
| value is None | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment