Suppose I have a method
def f(s:String *) = s.foreach( x => println(x) )
Now I have an array:
val a = Array("1", "2", "3")
How do I invoke f with elements of a as parameters?
EDIT:
So given a, I want to do the following:
f(a(0), a(1), a(2)) // f("1", "2", "3")
There is an operator for that:
This operation is defined in chapter 4.6.2 Repeated Parameters of The Scala Language Specification Version 2.9 and further explained in 6.6 Function Applications:
BTW your
ffunction can be simplified:Or better (equals sign is discouraged as it suggests that the method actually returns something, however it “only” return
Unit):