XML linearization in Scala



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.



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 this val children = ... How would you suggest change/fix it ?


No comments:

Post a Comment