I am trying to add some methods to a trait Traversableby pimping through implicit class.
But I seemed to be lost with the dash CanBuildFrom. Consider the following:
implicit class TraversableExt[+A, +Repr <: Traversable[A]](traversable: Repr) {
def debug[That](name: String)(implicit bf: CanBuildFrom[Repr, A, That]): That =
traversable.map{ a => println(name + ": " + a); a }(bf)
}
This is not an error:
Error: (21, 59) type mismatch
found: scala.collection.generic.CanBuildFrom [Repr, A, That]
required: scala.collection.generic.CanBuildFrom [Traversable [A], A, That]
traversable.map {a => println (name + ":" + a); a} (bf) ^
I assume that since Reprin CanBuildFrom[-Repr, -Elem, +To]is contravariant, and therefore mine Repr, whose upper limit Traversable[A]may not work.
, . - ?