I am trying to apply a partial function to a generic collection while returning a specific collection instead of Traversable of the original type.
Here's what I've tried (among other things):
def filter[A, B, C <: Traversable[A],Y<:B, D <: Traversable[Y]](xs: Option[D] with TraversableLike[A,Option[D]])(pf:PartialFunction[A,B]): D = {
xs.collect(pf)
}
def filter[A, B, C <: Traversable[A], D <: Traversable[B]](xs: D with TraversableLike[A,D])(pf:PartialFunction[A,B])(implicit ev: B =:= Option[Double]): D = {
xs.collect(pf)
}
Any ideas why implicit ev: B =:= Option[Double]
doesn't find the correct types?
I got inspiration from these posts:
Returning original collection type in generic method
How do I apply the enrich-my-library pattern to Scala collections?