In Scala, how do I define an anonymous function which takes a variable number of arguments?
scala> def foo = (blah:Int*) => 3
<console>:1: error: ')' expected but identifier found.
def foo = (blah:Int*) => 3
^
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It looks like this is not possible. In the language specification in chapter 6.23 Anonymous functions the syntax does not allow an
*after a type. In chapter 4.6 Function Declarations and Definitions after the type there can be an*.What you can do however is this: