Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Seq[String] to String*

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()

like image 391
vinayawsm Avatar asked Dec 13 '22 14:12

vinayawsm


1 Answers

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: _*)
}
like image 189
Berthur Avatar answered Jan 12 '23 09:01

Berthur