I would like to implicitly convert between a Scala XML Elem object and another representation of the XML element, in my case dom4j Element. I wrote the following implicit conversions:
implicit def elemToElement(e: Elem): Element = ... do conversion here ...
implicit def elementToElem(e: Element): Elem = ... do conversion here ...
So far so good, it works.
Now I also need collections of the specified elements to convert both methods. First, do I absolutely need to write additional conversion methods? Things didn't seem to work if I didn't.
I tried to write the following:
implicit def elemTToElementT(t: Traversable[Elem]) = t map (elemToElement(_))
implicit def elementTToElemT(t: Traversable[Element]) = t map (elementToElem(_))
This does not look too ideal, because if the conversion method accepts Traversable, it also returns Traversable. If I pass a list, I also get Traversable. Therefore, I assume that the transformation must be parameterized in some way.
, , ?