13 Anonymous Functions 2
- The first example is a method definition as we’ve seen before
-
The second, is like the previous slide, only assigned to a val, this is very, very roughly like the difference between
function foo(x, y) { return x + y; }
and
var foo = function(x, y) { return x + y; }
in JavaScript.
- The third, was briefly demonstrated in the previous slide, uses the shorter
_
placeholder syntax. However the usage on the left is rare in Scala, the_
notation for anonymous functions is mostly useful when passing them as parameter to higher order functions (functions that recieve or return other functions)