Will I Am
Will I Am

Reputation: 2672

Passing tuples to function parameters

Suppose I have this code:

def a(x:Int,y:Int):Int = x+y

def b:(Int,Int) = (1,2)

and I would like to accomplish:

  a(b)

What is the proper way of doing this? Also are there more efficient ways of calling a predefined multi-parameter function - in my case 8 - with the results of another function?

Upvotes: 4

Views: 1412

Answers (1)

j-keck
j-keck

Reputation: 1031

how about:

scala> (a _).tupled(b)
res0: Int = 3
  • a is a method. a _ gives you a partially applied function.
  • Function2.tupled creates a tupled version from your function.

Upvotes: 6

Related Questions