The following does not compile,
def echo(sep: String =" ", s: String*) = s.mkString(sep)
The desired function signature would have a first argument with default value and the rest, any number of strings.
The following does not compile,
def echo(sep: String =" ", s: String*) = s.mkString(sep)
The desired function signature would have a first argument with default value and the rest, any number of strings.
This is problematic.
Consider this:
echo("a", "b", "c") : is "a" now the seperator or does it belong to s? This cannot be decided by the compiler, since both would work.
A workaround can be to use multiple parameter lists.
def echo(sep: String =" ")(s: String*) = s.mkString(sep)
Now you can use:
echo()("a", "b", "c") //"a b c"
echo("a")("b", "c") //"bac"