I want to have a function that takes a variable number of functions, but I want them to not be evaluated until I actually used them. I could use the () => type syntax, but I would prefer to use the => type syntax, because it seems to be custom made for delaying evaluation.
When I try something like this:
def functions(fns: => String*) = "OK"
I get the error:
error: ')' expected but identifier found.
def functions(fns: => String*) = "OK"
Interestingly, it works fine when I change it to
def functions(fns: () => String*) = "OK"
What do I have to do to get my first function to work?
Since I submitted the issue:
https://issues.scala-lang.org/browse/SI-5787
It may yet happen.
Depending on your semantics, consider using Stream[String], which evaluates lazily.
Edit: Then I thought, didn’t someone just ask that? A couple of more answers here using implicits. I think my answer there should be up-voted just for “This used to happens first”.