#anonymous-functions #functions #scala

The following expression creates a successor function for integers:

var inc = (x:Int) => x+1


Variable inc is now a function that can be used the usual way:

var x = inc(7)-1
If you want to change selection, open document below and click on "Move attachment"

Scala Anonymous Functions
ts called function values. Scala supports first-class functions, which means you can express functions in function literal syntax, i.e., (x: Int) => x + 1, and that functions can be represented by objects, which are called function values. <span>The following expression creates a successor function for integers: var inc = (x:Int) => x+1 Variable inc is now a function that can be used the usual way: var x = inc(7)-1 It is also possible to define functions with multiple parameters as follows: var mul = (x: Int, y: Int) => x*y Variable mul is now a function that can be used the usual way: println(