Is there a Scala equivalent of the Python list unpack (a.k.a. “*”) operator?

后端 未结 4 1336
感动是毒
感动是毒 2021-02-07 01:16

In Python, we have the star (or \"*\" or \"unpack\") operator, that allows us to unpack a list for convenient use in passing positional arguments. For example:

         


        
4条回答
  •  萌比男神i
    2021-02-07 01:49

    Another way of unpacking a list:

    val a :: b :: c :: _ = argList
    val z = ThreeValues(a, b, c)
    

提交回复
热议问题