Goal one: In-depth understanding of higher order functions
Higher order functions
1.1 Concepts
Scala mixes object-oriented and functional features,
We usually use an expression that can be passed as a parameter to a method called a function.
In functional programming languages, functions are "prime citizens",
Higher-order functions include: functions as Values , anonymous functions , closures , currying , and so on.
1.2 function as a value (hence the name Incredibles: The value of the function as the return value)
1.3 Anonymous functions
In Scala, you don't need to give each function a name, and a function that doesn't assign a function to a variable is called an anonymous function.
Since Scala can automatically infer the type of parameters, it can be written to streamline some
Do you remember the magic underline? That's the way to end it.
1.4 Converting a method into a function
In Scala, the difference between a method and a functional one is that the function can be
Pass the parameter to the method, but the method can not be converted into a function,
The Magic underline has appeared
1.5 currying
Currying refers to the process of turning a method that accepts two parameters into a new method of accepting a parameter.
First method: Def m (x:int) = (y:int) =>x*y
Second method: Def m (X:int) (Y:int) =x*y
The following section describes implicit conversions and hermit parameters
Merry Christmas
Scala Advanced Features-01