Implicit conversion between Scala collection types

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.

, , ?

+5
2

, , , , , . , scala ( ): http://www.artima.com/scalazine/articles/scala_collections_architecture.html

, List.map(...) ( TraversableLike, ) ... .

Update:

, , TraversableLike.map(...). , . , scala ( , :-)):

case class Element(e: Elem)
implicit def elemToElement(e: Elem): Element = Element(e)
implicit def elementToElem(e: Element): Elem = e.e

val a: List[Element] = List(<a/>, <b/>, <c/>)
val b: List[Elem] = List(Element(<a/>), Element(<b/>), Element(<c/>))
val c: Set[Element] = Set(<a/>, <b/>, <c/>)

, ?

+2

, . ,

val listOfElements = listOfElems map elemToElement(_)

, , , . , .

+1