John Doe John Doe - 1 month ago 7
Scala Question

How to transform List of tuples to multiple tuples?

I want to have a method that builds up query parameters for

def withQueryString(parameters: (String, String)*): WSRequest
. In particular, I have the following method:

def toParams: Seq[(String, String)] = {
val params = List(
("firstName" -> "john"),
("lastName" -> "doe"),
("age" -> "35"),
("ssnr" -> "1234")
)
params
}


The problem is that the method
withQueryString
requires
(String, String)*
instead of
Seq[(String, String)]
. How can I make this conversion?

Answer

You can unpack the Seq using :_*:

val result = withQueryString(toParams: _*)
Comments