Any way to simplify the following? or reduce the boilerplate code with another function?
scala> val ns = <foo><bar id="1"><tag>one</tag><tag>uno</tag></bar><bar id="2"><tag>two</tag><tag>dos</tag></bar></foo>
ns: scala.xml.Elem = <foo><bar id="1"><tag>one</tag><tag>uno</tag></bar><bar id="2"><tag>two</tag><tag>dos</tag></bar></foo>
scala> (ns \\ "bar" filterNot{_ \\ "@id" find { _.text == "1" } isEmpty}) \\ "tag"
res0: scala.xml.NodeSeq = NodeSeq(<tag>one</tag>, <tag>uno</tag>)
I could only find a minor improvement, the
find/isEmptytest can be replaced withexists:Edit after clarifying comment:
That’s a really nice idea! Try this for size:
I used a predicate instead of hard-coding the attribute value comparison.