Implicit conversion of Traversable contents in Scala

Viewed 847

I am trying to create an implicit converter that would would use a implicit converter that's currently in scope (eg. A => B) and would be able to convert any type of Traversable[A] to Traversable[B].

So far I got:

implicit def convertLists[A, B](from: Traversable[A])(implicit conv: A => B): Traversable[B] = from.map(conv)

This however does not work with:

val listOfB: List[B] = convertLists(List[A]())

If I change Traversable to List, then it works fine, eg:

implicit def convertLists[A, B](from: List[A])(implicit conv: A => B): List[B] = from.map(conv)

Do I need to add anything else to allow the converter to accept any subclass of Traversable?

2 Answers
Related