Scala: Expand List of Tuples into variable-length argument list of Tuples
functional-programming, scala
Solution
You need to add `:_*`.
scala> test_func(List(("1","2"),("3","4")):_*)
works!
scala> test_func(Seq(("1","2"),("3","4")):_*)
works!
scala> test_func(Array(("1","2"),("3","4")):_*)
works!
Problem
I'm puzzled on how to expand List/Seq/Array into variable-length argument list. Given that I have test_func function accepting tuples: ``` scala> def test_func(t:Tuple2[String,String]*) = println("works!") test_func: (t: (String, String)*)Unit ``` Which works when I pass tuples: ``` scala> test_func(("1","2"),("3","4")) works! ``` From reading the Scala reference I've got strong impression that the following whould work as well: ``` scala> test_func(List(("1","2"),("3","4"))) <console>:9: error: type mismatch; found : List[(java.lang.String, java.lang.String)] required: (String, String) test_func(List(("1","2"),("3","4"))) ^ ``` And one more desperate attempt: ``` scala> test_func(List(("1","2"),("3","4")).toSeq) <console>:9: error: type mismatch; found : scala.collection.immutable.Seq[(java.lang.String, java.lang.String)] required: (String, String) test_func(List(("1","2"),("3","4")).toSeq) ``` How to expand List/Seq/Array into argument list? Thank you in advance!