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)*
?
You need to convert the map to a Seq
and mark it as a varargs element like this:
myFunction(p.toSeq: _*)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With