the difference between foo _ and foo(_) (or foo(_, _) and so on) has always been a puzzler factory.
if the choice is between foo _ and foo(_), then losing the first option isn't bad, but if the choice is between foo _ and foo(_, _, _, _, _, _) then it starts feeling different.
but in the wild, perhaps most uses of foo _ would also compile simply as foo because a function type is already expected?
personally, I think I tend to write foo _ even when just foo would compile, just to explicitly signal to the reader that foo is definitely not being called.
For 0 argument the only alternative is () => foo(). Especially now that automatic eta-expansion of 0-arg methods is deprecated.
True, but I think the benefit of
outweighs having to explicitly eta-expand for the 0-ary case.
this is being taken up at https://github.com/lampepfl/dotty/issues/2570
foo(_, _, _, _, _, _) will never be necessary because just foo will always work
@adriaanm Or stop parenthesis injection for nullary functions.
Dotty's doing that, but I don't think we can make everyone insert the needed () in their code base in 2.13.
Carried over from #489:
Currently, http://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html#method-values says:
The expression
e _is well-formed ifeis of method type or ifeis a call-by-name parameter. [...]
Ifeis a parameterless method or call-by-name parameter of type=> T,e _represents the function of type() => T, which evaluatesewhen it is applied to the empty parameter list().
Since we've removed eta-expansion for nullary methods, for consistency we should also deprecate and drop the last part re: "parameterless method or call-by-name parameter". Those will need to be written explicitly using () => e.
Eventually (ideally), all method references will be eta-expanded regardless of expected type, and method value syntax will be dropped since it's redundant.
this is happening in Dotty eventually, but out of scope for Scala 2
Most helpful comment
For 0 argument the only alternative is
() => foo(). Especially now that automatic eta-expansion of 0-arg methods is deprecated.