Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@eyston
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyston/268add01dc4287553820 to your computer and use it in GitHub Desktop.
Save eyston/268add01dc4287553820 to your computer and use it in GitHub Desktop.
// is there a way to make this an awesome for comprehension or whatever?
// or maybe a built in Map method to do what I want? ;p
val codes: List[String] = ...
val configs: Map[String, Configuration] = ...
val defaultConfig: Configuration = ...
val config: Configuration = codes
.find(configs.contains) // find the first code that the configs map contains
.flatMap(configs.get) // grab the config for that first code
.getOrElse(defaultConfig) // if no config, get the default config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment