Created
May 6, 2011 01:29
-
-
Save etorreborre/958304 to your computer and use it in GitHub Desktop.
A great configuration trick with implicits and default values!
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
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