First we will see what’s the difference between no-parenthesis and empty-parenthesis methods. We will see what role this difference plays when converting methods to functions. Eta-expansion as a mechanism for transforming methods into functions will be explained, as well as techniques for manual conversion. Finally, partially applied functions and curried functions are explained in the context of the problem at hand.
If it’s empty, it still exists
Let’s say we have these two creatively named methods:
def methodA(s: String) = ???
def methodB(f: () => String) = ???
We want to see which invocations of these methods pass and which fail when we feed them with different values for parameters.
Let’s start from this very simple method f:
def f = "foo"
methodA(f)
methodB(f) // error!
methodA(f()) // error!
methodB(f()) // error!
Since methodA() takes a String, it will have no problems taking f as a parameter.