パスのリストがあります:
val paths = List(List("foo"), List("bar", "a"), List("bar", "b"))
それを Scalaz Tree で表現したい:
def pathsToTree(root: String, paths: List[List[String]]): Tree[String] = ???
結果:
pathsToTree("paths", paths)
=> "paths".node("foo".leaf, "bar".node("a".leaf, "b".leaf))
http://eed3si9n.com/learning-scalaz/Tree.htmlTreeLoc
からいくつか読んだことがありますが、左/右または子インデックスを使用するのはかなり面倒です。次のようなことを想像します:
paths.foldLeft(root.node()) { case (acc: Tree[String], path: List[String]) =>
acc // how to add all the items from `path` to the tree?
}
find
and setTree
orを使用できるように見えますmodifyTree
が、それは非常に非効率的です。