Nov. 14th, 2013
funny coding style
Nov. 14th, 2013 01:36 pm
override def dropPrefix = new PropsFromMap({
val mapWhereKeysAreSplitIntoPrefixAndTheRest = map map(kv => (kv._1.split("\\.", 2), kv._2))
val mapWithDroppedPrefix = mapWhereKeysAreSplitIntoPrefixAndTheRest map (kv => (kv._1 drop 1 mkString, kv._2))
val mapWithNonemptyKeys = mapWithDroppedPrefix filter (kv => !kv._1.isEmpty)
mapWithNonemptyKeys
})
val sut = props("a.b.c.d" -> "<<ABCD>>",
"x" -> "<<X>>",
"a.d.x.y" -> "<<ADXY>>")
sut.findAllHaving("c").value must_== Good("<<ABCD>>")
sut.findAllHaving("a").value.isBad must beTrue
sut.findAllHaving("ab").value.isBad must beTrue
sut.findAllHaving("y.d").value must_== Good("<<ADXY>>")
What happens here.
First, I create a property tree with three keys (that's like ldap, kind of)
Then I try to find a subtree of all those keys that contain "c" as a subkey.
And I get it's unique value (will fail if the value is not unique.
Like in the second example, I find a subtree of those having "a" in the keys; and it is not a singleton, so it's bad.
In the third example the resulting subtree is empty, so retrieving a unique value fails again.
In the third example the key is compound, and actually not even sequential.
Maybe I should rename the method. Or maybe not.
What do you think?
See, what I do now, is grab the body of html, transform it into a tree of knowledge, and then extract knowledge. There's a lot of garbage there; eliminating it is cumbersome, but I can just ignore it, the way you ignore it when you look at a web page.

