Decomposing tuples in function arguments

后端 未结 3 1927
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:34

    object RandomExperiments extends App{
      def takeTuple(t:(Int,Int))=print (s"$t ${t._1}\n")
      takeTuple(1,3)
      takeTuple((1,3))
      takeTuple(((1,3)))
    
    }
    

    prints:

    (1,3) 1
    (1,3) 1
    (1,3) 1
    

提交回复
热议问题