Reputation: 113
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
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
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