Skip to content

Instantly share code, notes, and snippets.

@michaeldfallen
Last active August 29, 2015 13:57
Show Gist options
  • Save michaeldfallen/9808250 to your computer and use it in GitHub Desktop.
Save michaeldfallen/9808250 to your computer and use it in GitHub Desktop.
Namespacing Keys
Interesting thought on how to do namespacing with keys:
class BaseK(name:String) {
implicit val parent = this
def value = this.name
}
class K(name:String)(implicit parent: BaseK) extends BaseK(name) {
override def value = parent.value + "." + name
}
trait k {
val foo = new BaseK("foo") {
val bar = new K("bar")
}
val baz = new BaseK("baz") {
val boz = new K("boz")
}
}
then k.foo.bar.value = "foo.bar"
but k.foo.boz or k.baz.bar would be caught as compile errors.
This has the benefit over our current approach that nesting is guaranteed by the compiler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment