user3607625 user3607625 - 1 year ago 77
Scala Question

How to pass a tuple3 as an argument to function?

I'm trying to pass a tuple as an argument to function. Unfortunately i can't do this. Can you give me some tips?

val t = Tuple3(3, "abc", 5.5);
def fun(x: (Int, String, Double) = {
x.productIterator.foreach(i => println("Value: " + i));

Answer Source

There's a missing closing parenthese and you called def(t) instead of fun(t). Note that you don't need to indicate the constructor Tuple3 :

val t = (3, "abc", 5.5);
def fun(x: (Int, String, Double)) = {
  x.productIterator.foreach(i => println("Value: " + i));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download