Skip to content

Instantly share code, notes, and snippets.

@RSchulz
Created July 13, 2011 23:25
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 RSchulz/1081572 to your computer and use it in GitHub Desktop.
Save RSchulz/1081572 to your computer and use it in GitHub Desktop.
package rrs
trait Configurable
{
val dir = "/foo/bar"
val env = "config1.cfg"
implicit val cde = (dir, env)
}
class Config(val name: String)
{
def apply(sect: String)(param: String): String =
"%s|%s=<don't ask me>".format(sect, param)
}
object Config
{
def config(file: String)(implicit de: (String, String)): Config =
new Config("%s<%s, %s>".format(file, de._1, de._2))
}
class ConfigMe
extends Configurable
{
import Config._
val cfg = config("cf1.cfg")
val v1 = cfg("foo")("bar")
val v2 = config("cf1.cfg")("foo")("bar")
val v3 = (config("cf1.cfg"))("foo")("bar")
val v4 = config("cf1.cfg").apply("foo")("bar")
}
/*
Config.scala:32: error: type mismatch;
found : java.lang.String("foo")
required: (String, String)
val v2 = config("cf1.cfg")("foo")("bar")
^
Config.scala:34: error: type mismatch;
found : java.lang.String("foo")
required: (String, String)
val v3 = (config("cf1.cfg"))("foo")("bar")
^
two errors found
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment