Seq
is a trait that List
implements.
If you define your container as Seq
, you can use any container that implements Seq
trait.
scala> def sumUp(s: Seq[Int]): Int = { s.sum }
sumUp: (s: Seq[Int])Int
scala> sumUp(List(1,2,3))
res41: Int = 6
scala> sumUp(Vector(1,2,3))
res42: Int = 6
scala> sumUp(Seq(1,2,3))
res44: Int = 6
Note that
scala> val a = Seq(1,2,3)
a: Seq[Int] = List(1, 2, 3)
Is just a short hand for:
scala> val a: Seq[Int] = List(1,2,3)
a: Seq[Int] = List(1, 2, 3)
if the container type is not specified, the underlying data structure defaults to List
.