complete
returns a function. When you call complete("yeah")
, you are supplying the "yeah"
parameter to that function (they call it the magnet).
So to do something similar you would write:
def testFunc: Int => Unit = (i: Int) => println(i)
Putting it together with calling a method on an object Test
:
def testFunc: Int => (Test => Unit) = (i: Int) => {
(test: Test) => println(i)
}
Because of the way =>
associates to the right and type inference, this could be rewritten:
def testFunc: Int => Test => Unit = i => test => println(i)
It is then either very confusing or natural (the parameters mirror the types exactly).
So when in the tutorial they say it is equivalent, the authors of the library go to some length to make it look like it is "equivalent" by returning functions, it is not something that is built-in in the Scala syntax.