I want to define a transformation of a generic collection.
def transform[S<:GenIterable[T],T](s:S):S = s.zipWithIndex
This throws:
type mismatch; found : scala.collection.GenIterable[(T, Int)] required: S
I have to declare S as a parameterized GenIterable in the function definition. I'd like to specify an output type of "whatever the collection type was that created S, except parameterized with [(T,Int)]", so that I'm guaranteed to get the same collection type back, and not just GenIterable.
How can I make that happen?
That's my stub on it:
Signature is horrible, it may be somewhat simplified (or obscured) by replacing
Twith_.Trying it out:
The key is to use
Liketrait because it carries the type of the collection being used. Then, implicit conversions take care of the rest. Note, howMapis handled. It seems that implicit conversions default to convertingIterabletoList, which makes sense.