Scala: Can I convert an Option to varargs?

I have an Option:

val myOption: Option[Int] = fooBar()

And a method that takes a varargs param:

def myMethod(a: String, b: Int*) = {...}

Is there any way to pass the option to the method as a varargs param? i.e. if the option is Some(3) then pass 3, and if it is None then pass nothing.

Experimenting with the answer to scala: How to pass an expanded list as varargs into a method? I tried explicitly typing the argument:

myMethod("xyz", myOption: _*)

but the compiler complains that it requires a Seq[Int]. It seems that Option does not implement Seq and there is no predef implicit conversion.

Given that the compiler wants a Seq, I can of course pass myOption.toList: _*, but is there a nicer way?

Answers


myMethod("xyz", myOption.toSeq: _*)

Need Your Help

exchange web services restriction paths

exchange-server ews exchange-server-2010

I have done a bit of searching and am unable to find a list of legal properties for use with the FindItem <Restriction> element, specificially what can I use in <IsEqualTo><FieldURI

reset_session not doing anything

ruby-on-rails-4 torquebox

I'm building a rails 4 app with JRuby on Torquebox, and running into a weird issue with the sessions. I'm using the devise gem to handle authentication which works well, except that as per the rails

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.