Last active
August 29, 2015 13:57
-
-
Save michaeldfallen/9808250 to your computer and use it in GitHub Desktop.
Namespacing Keys
This file contains 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
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