Decomposing tuples in function arguments

后端 未结 3 1924
Happy的楠姐
Happy的楠姐 2020-12-29 02:02

In python I can do this:

def f((a, b)):
    return a + b

d = (1, 2)
f(d)

Here the passed in tuple i

3条回答
  •  抹茶落季
    2020-12-29 02:46

    With the upcoming Scala 3release schedule, and the improved tupled function feature, this will become possible:

    // val tuple = (1, 2)
    // def f(a: Int, b: Int): Int = a + b
    f.tupled(tuple)
    // 3
    

    Play with it in Scastie

提交回复
热议问题