This is a follow-up to my previous question. I would like to linearize an XML tree eagerly (not lazy). I assume for simplicity that an XML tree is a tree of Elem
nodes, so I am transforming an XML to a sequence of Elem
.
import scala.xml.{Elem, Node}
import PartialFunction._
def linearize(node: Node): List[Node] = {
val children = node.child.filter(cond(_) {case _: Elem => true}).toList
children match {
case Nil => List(node)
case list => node :: list.flatMap(linearize)
}
}
It seems working but I don't like that val children = ...
How would you suggest change/fix it?