Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from Map[String,Any] to (String, String)*

Tags:

scala

A function takes an input as follow:

myFunction("param1" -> "value1", "param2" -> "value2")

Parameter type in myFunction is (String,String)*. Now, I want to store these parameters in a map object like this:

val p = Map("param1" -> "value1", "param2" -> "value2")

The reason is because I want to pass p around before I pass it into myFunction like this: myFunction([converting p to (String,String)* here]) and I cannot change the parameter type of myFunction. How can I convert p to (String, String)*?

like image 434
mmdc Avatar asked May 18 '15 14:05

mmdc


1 Answers

You need to convert the map to a Seq and mark it as a varargs element like this:

 myFunction(p.toSeq: _*)
like image 132
Chirlo Avatar answered Sep 17 '22 00:09

Chirlo