Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Created May 6, 2011 01:29
Show Gist options
  • Save etorreborre/958304 to your computer and use it in GitHub Desktop.
Save etorreborre/958304 to your computer and use it in GitHub Desktop.
A great configuration trick with implicits and default values!
case class Config(name: String="none")
def methodNeedingAConfig(implicit config: Config = Config()) = config.name
// by default there is no config
methodNeedingAConfig === "none"
// just add one in the current scope
implicit val myConfig = Config("some")
// that's the config being used now!
methodNeedingAConfig === "some"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment