Kotlin: Idiomatic way to call (Int, Int) -> Int with a Pair<Int, Int>?

Viewed 1125
fun sum(a: Int, b: Int) = a + b
val x = 1.to(2)

I'm looking for:

  1. sum.tupled(x), or
  2. sum(*x)

Of course, none of the above compiles with Kotlin 1.1.3-2. So am I stuck with sum(x.first, x.second)?

Edit:

Generalizing on the useful answers, I think this is the closest thing for now:

fun <P1, P2, R> Function2<P1,P2,R>.tupled(x: Pair<P1, P2>): R = invoke(x.first, x.second)
3 Answers
Related