Scala :Returning a Function with variable argument from another function -


my requirement return function function in scala takes variable argument i.e while executing returned function , can pass multiple argument @ runtime.

my code looks :

object varargtest {   def getfunction(): (map[string, string],map[string, any]*) => any={     (arg:map[string,string], arg2:map[string,any]*) => "random"//this gives compilation error   } } 

in code , want return function take , map[string,string] 1 argument ,while other map[string,any] should optional it.

but compilation error in return statement follow:

type mismatch; found : (map[string,string], map[string,any]) required: (map[string,string], map[string,any]*) ⇒ 

can , have missed here? note: requirement returned function can take either 1 argument (map[string,string]) or can take 2 arguments max (map[string,string], map[string,any])

thanks

it's impossible use varargs in anonymous function. can piece of code working making returned function nested instead of anonymous this:

object varargtest {   def getfunction(): (map[string, string],map[string, any]*) => = {     def nestedfunction(arg:map[string,string], arg2:map[string,any]*) = "random"     nestedfunction   } } 

however since don't need multiple instances of map[string, any] either none or one, better off using option[map[string, any]], providing none when not needed.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -