I have a function that accepts String*
as parameters. I am implementing another function that takes Seq[String]
(or an array of string) as a parameter but needs to call the previous function with that parameter. Is there any way to make the conversion?
def foo (s: String*) = {
...
}
def callFoo (s: Seq[String]) = {
foo (s) // this throws an error
}
foo
function can be called as foo("string1", "string2", "string3")
. But I want to only call callFoo(Seq[String])
function and get the result from foo()
You can adapt your Seq
to the variable argument list that foo
expects using the _*
operator, as follows:
def callFoo (s: Seq[String]) = {
foo (s: _*)
}
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