4

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

1 Answer 1

12

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: _*)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.