Let's say I want to extend the functionality of SeqLike
:
import collection.SeqLike
implicit class Test[A, Repr <: SeqLike[A, Repr]](val sq: Repr) extends AnyVal {
def foo(): Repr = sq
}
Then this doesn't work:
Vector(1, 2, 3).foo()
Also not:
new Test(Vector(1, 2, 3)).foo()
<console>:41: error: inferred type arguments
[Nothing,scala.collection.immutable.Vector[Int]]
do not conform to class Test's type parameter bounds
[A,Repr <: scala.collection.SeqLike[A,Repr]]
new Test(Vector(1, 2, 3)).foo()
^
Only this works:
new Test[Int, Vector[Int]](Vector(1, 2, 3)).foo()
How can I make the implicit class work?