Thanks for the help. I ended up using a slight variation on your code:
def walkPath[A](t: Tree[A], path: List[A]): TreeLoc[A] =
path.tail.foldLeft(t.loc)((t, e) => t.findChild(_.rootLabel ==
def graft[A](t: Tree[A], to: List[A], from: List[A]): Tree[A] =
walkPath(t, to).insertDownLast(walkPath(t, from).tree).root.tree
Basically the same except for the getOrElse and turning the graft result
into a tree. In order to get the "transplant" behavior I was hoping for --
i.e. "take this branch and move it here" I had to add one additional method:
def prune[A](t: Tree[A], path: List[A]): Tree[A] =
By combining graft and prune I was able to create my transplant method:
def transplant[A](t: Tree[A], to: List[A], from: List[A]): Tree[A] =
prune(graft(t, to, from), from)
I will probably change the syntax around a little bit, but that's basically
the functionality I was looking for.
Thanks again for the help!