Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variable-length arguments to another function expecting the same?

How to code this right in Scala?

def myFun(strings: String*) = {
  // do something...
}

def myWraper(strings: String*) = {
  // do something else and then call myFun with the dame input
  myFun(strings)
}

I've tried putting an asterisk like

def myWraper(strings: String*) = {
  // do something else and then call myFun with the dame input
  myFun(strings*)
}

But this doesn't seem to work...

like image 889
Ivan Avatar asked Apr 16 '12 02:04

Ivan


1 Answers

Try this:

 myFun(strings: _*)

You need to tell it to split strings up across the varargs.

like image 111
dhg Avatar answered Sep 28 '22 03:09

dhg