Yes, it’s very possible:
>> def perform(functions:() => Unit*) = for (f <- functions) f()
>> perform(() => println("hi"), () => println("bye"))
hi
bye
perform: (functions: () => Unit*)Unit
Remember that duplicate options are displayed as Seq[TheType]. In this case Seq[() => Unit], although this can be quite confusing, since it seems like it *should have a higher priority, but it is not.
Note that using parentheses gives the same type:
>> def perform(functions:(() => Unit)*) = for (f <- functions) f()
perform: (functions: () => Unit*)Unit
Happy coding.
user166390
source
share