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

后端 未结 4 1269
感动是毒
感动是毒 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条回答
  •  终归单人心
    2021-02-07 01:50

    There is something similar for functiones: tupled It converts a function that takes n parameters into a function that takes one argument of type n-tuple.

    See this question for more information: scala tuple unpacking

    Such a method for arrays wouldn't make much sense, because it would only work with functions with multiple arguments of same type.

提交回复
热议问题