1. Function
Function is a very flexible operation logic, the function may be passed a flexible approach, provided that the receiving method is the same type of function type
The benefits of functional programming: What do you want to call the appropriate method (fliter, map, groupBy, sortBy), specifically how you want to do, was introduced to the appropriate function
One of the characteristics of functional programming is to support chained program (non-stop calls the function)
1.1 method is more succinct definition function (_)
Previous form
Concise form
"_" Corresponds to a placeholder, the value assigned to traverse out placeholder
The placeholder appears twice, it will think there are two parameters, since here is a parameter, if using the following expression squaring will complain
At this time, if wanted squared math package may be used to achieve the objective
1.2 the difference between functions and methods
Can function as an argument to the function of the method [nature] is a reference type, but the method does not work
The following examples give method seems to be the method as a parameter
m is equivalent to m _ syntactic sugar, generates a function m _
Question 1: Why are passed to the method m in the method can perform the corresponding operation it?
Because when passing a method name, Scala will convert the internal function, or a function of the actual incoming
Question 2: m _ This syntax is generated in the end, like a method m arithmetic logic function or a function call generated m way to do that
M _ grammar so that a function is generated, the generation function then calls method m