In the Scala code
val s = Set(List(1,2,3).toSeq:_*)
how does the toSeq:_*
syntax work? I know what the code does, I know what toSeq
does, I understand List(1,2,3).toSeq:Seq[Int]
. Is toSeq:_*
a special case?
In the Scala code
val s = Set(List(1,2,3).toSeq:_*)
how does the toSeq:_*
syntax work? I know what the code does, I know what toSeq
does, I understand List(1,2,3).toSeq:Seq[Int]
. Is toSeq:_*
a special case?
The toSeq
isn't accomplishing anything here, and should be omitted. The following is equivalent:
Set(List(1, 2, 3): _*)
(Or even better, just write List(1, 2, 3).toSet
.)
Since you say you know what the code does, I'll assume you understand the _*
type annotation that marks the list as a sequence argument (if not, see section 4.6.2 of the language specification). This will work on any Seq
, including List
, so converting the list explicitly with toSeq
is just extra clutter.