Open bbarker opened 6 years ago
I'm not sure it's worth putting these helper... With a clean ADT, traversing and transforming trees is really simple, for example here how I would what is asked on the linked question:
def traverse(n: Node): Node =
n match {
case g @ Group(ns) => g.copy(nodes = ns.map(traverse))
case e @ Elem(_, _, _, _, ns) => e.copy(child = ns.map(traverse))
case Text(_) => Text("")
case x => x
}
This seems to be a pervasive issue, though it usually doesn't cause an issue in rendering. However, when it does, it is fairly annoying:
https://stackoverflow.com/questions/38469002/how-to-strip-text-from-xml-string-in-scala
I suggest we have a way like this to rewrite rules. Not sure if we want to implement the full version from scala.xml - haven't looked at it yet, but I suspect we could do something much simpler, as with a tail recursive filter.