Pre-2.13 one could use
Seq as a parameter type for a lot of things that are some sort of collection:
def foo(xs: Seq[Int])
and you could pass e.g.
Buffer and so on to it.
Now in 2.13 the collections library got rewritten and
collection.immutable.Seq and not
collection.Seq. So you can’t pass anything mutable to
foo in the example.
Solution #1: use
collection.Seq instead of
Sure. But it’s not short and sweet. I’d hate to write
def foo(xs: scala.collection.Seq[Int]) everywhere.
Solution #2: use
Yes, technically this is the right solution. It is the top-level collection type that has most of the collection methods, and the name is descriptive and precise.
But it’s not short and sweet. I’d hate to write a lot of
def foo(xss: Iterable[Iterable[Int]], yss: Iterable[Iterable[Int]]) and so on.
I prefer short names on anything that is part of the “core language” (e.g.
val etc.), so that it gets out of the way as much as possible, letting the actual business logic stand out better. And such I’ve used
Seq all over the place for collections, even though it might not be “technically” correct. I.e. in the context of most code I write I don’t care if something is “iterable” or whatever that might even mean, I just want to map over it or filter it.
I suggest adding a short type alias for
Iterable that serves as the standard top-level collection type.
Coll is a good candiate.
Thus I propose that
type Coll[A] = Iterable[A] be added to the standard library.