我有anti-xml Elem,像这样(自动生成的数据):
<library>
<bookshelf number="0">
<book year="1997" title="Puzzled Coordinators" author="Lily Williams"></book>
<book year="2005" title="Jittery Fare" author="Lucy Taylor"></book>
<book year="2001" title="Dizzy Jurisdiction" author="Lucy Robinson"></book>
</bookshelf>
<bookshelf number="1">
<book year="1997" title="Bashful Trusts" author="Lucas Wilson"></book>
<book year="2003" title="Outrageous Consequences" author="Byron White"></book>
<book year="1992" title="Irritated Accusations" author="Anne Roberts"></book>
</bookshelf>
</library>
我想对其应用几个转换,例如:
val transforms: Seq[...] = ...
val result = transforms.foldLeft(library)(l,t) => t(l))
但我只得到了这个解决方案:
val transforms: Seq[Elem => Zipper[Node]] = Seq(
x => x \\ "book" filter (_.attrs("year").toInt > 2000) unselect,
x => x \\ "book" filter (_.attrs("title").contains("J")) unselect
)
val result = transforms.foldLeft(lib)((l,t) => t(l).head.asInstanceOf[Elem])
有没有办法获得更好的转换类型(Elem => Elem)并避免那些丑陋的演员表?