How to pass variadic arguments while adding another one in Scala?

Consider such methods:

def clearlnOut(coll : Any*)
{
  clearOut(coll:_*,"\n") // error
}
def clearOut(coll : Any*)
{
  ...

The compiler says:

error: no `: _*' annotation allowed here (such annotations are only allowed in arguments to *-parameters)

Now I am puzzled. It is clear case of using variadic arguments, so how to pass such augmented "collection" properly?

Answers


Try this:

def clearlnOut(coll : Any*) {
  clearOut(coll ++ "\n")
}

UPDATE: much better version suggested by @Rex Kerr (see comment below):

def clearlnOut(coll : Any*) {
  clearOut((coll :+ "\n"): _*)
}

Need Your Help

ASP.NET web application inside app / service

.net asp.net-mvc

Can I host an ASP.NET (MVC5 if it matters) webapplication be hosted inside a normal console, UI or windows-service application? Where to start without web.config?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.