Last active
December 18, 2015 15:09
Using getOrElse to provide a default value when looking up a key in a Map[String,String] ... More details at: http://sdanzig.blogspot.com/2013/06/the-option-design-pattern.html
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
// Sample usage | |
Console.println("Last name of harry is: "+ | |
firstToLastNameMap.get("harry").getOrElse("not found")) | |
Console.println("Last name of harry is: "+ | |
firstToLastNameMap.get("sam").getOrElse("not found")) | |
/* | |
Output: | |
Last name of harry is: smith | |
Last name of harry is: not found | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment