user3607625
user3607625

Reputation: 113

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));
}
def(t);

Upvotes: 1

Views: 50

Answers (2)

Chris C
Chris C

Reputation: 229

You are missing a bracket after your method declaration. Also you need to run using fun(t).

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

Upvotes: 0

cheseaux
cheseaux

Reputation: 5325

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));
}
fun(t);

Upvotes: 1

Related Questions