Considering this code:
def myMap[T, S](seq: S)(implicit ev: S <:< Seq[T]): S =
seq.map { x => x }
The compiler complains:
error: type mismatch;
found : Seq[T]
required: S
Obviously seq.map { x => x }
returns a Seq[T]
, instead of S
.
But S
is a subclass of Seq[T]
, and map
should be able to build an S
to another S
.
How to write such a function receiving any Seq
and return original type, not just Seq
?