John Doe John Doe - 1 year ago 57
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")

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

Answer Source

You can unpack the Seq using :_*:

val result = withQueryString(toParams: _*)