I would like to implement method that takes arbitrary Seq[T] and returns Seq[T] as well. But when String is provided it should also return String.
Passing String works due to some implicit conversion from String to WrappedString extends IndexedSeq[Char], but I get Seq[Char] in return. Is it possible to get String back?
val sx: Seq[Int] = firstAndLast(List(1, 2, 3, 4))
val s1: Seq[Char] = firstAndLast("Foo Bar")
val s2: String = firstAndLast("Foo Bar") //incompatible types error
def firstAndLast[T](seq: Seq[T]) = Seq(seq.head, seq.last)
firstAndLast() implementation is irrelevant, it is only an example.