In scala I have a function that takes a series of arguments, and I have a Seq with the values that correspond exactly, is there a nice way to pass the sequence as the arguments?
val x = Seq(1,2,3)
def test(a: Int, b: Int, c:Int) {
println(a)
}
test(x.something?)
@hobosarefriends I suspect (but I’m not sure) that this will only work with varargs functions:
def printAll(strings: String*) {
strings.foreach(println)
}
val x = Seq("1","2","3")
printAll(x:_*)
Since Scala can’t determine the length of the Seq at compile time (in general), I don’t think it will accept passing it to a fixed arity function
Aww.. well I guess I’ll just have to destructure it and pass them seperately. Thanks for the help!
There’s also a Scala gitter on which people are sometimes helpful, might make sense to check it there too 🙂
I could but I’m afraid of everyone there 😆
to illustrate what I meant earlier:
try { val Seq(a,b,c,d) = Seq(1,2,3); d } catch { case e: Exception => 1 }
res6: Int = 1
it can only decide at runtime if the pattern match will succeedaaaaah, yeah that makes sense.