No, this isn't a CanBuildFrom
issue. I've defined a typeclass on a method but that method is not picking up for a List
:
trait HeadLast[Elem, Coll]{
def get(coll: Coll): (Elem, Elem)
}
class DoStuff[-T]{
def stuff[C, TT <: T](coll: C, value: TT)(implicit hl: HeadLast[TT, C]) ={
val (h, l) = hl get coll
(h == value || l == value)
}
}
object DoStuff{
implicit def htrav[Elem, Repr <: TraversableLike[Elem, Repr]] = new HeadLast[Elem, Repr]{
def get(coll: Repr) = (coll.head, coll.last)
}
}
So, could it be an issue with variance? Is this just an implicit that won't be picked up and I need to specify one for each of List
, Set
, etc.?