As mentioned in the title i don't understand why these function doesn't compile and are asking for a Seq.
def f1[V <: Seq[Int]](v: V): V = v.map(_ + 1)
def f2[V <: Seq[Int]](v: V): V = v.zip(v).map{ case (a, b) => a + b }
error: type mismatch;
found : Seq[Int]
required: V
I have the following workaround :
def f1[V <: Seq[Int]](v: V): V = v.map(_ + 1).asInstanceOf[V]
def f2[V <: Seq[Int]](v: V): V = v.zip(v).map{ case (a, b) => a + b }.asInstanceOf[V]
But i would like to know if it exist another solution. If not what is the cost of casting something like that, is it O(1) or O(n) with n the Seq size.