Lambda expressions revisited
In this section, we will explore the syntax of lambda expression in more depth. So far, we used them without formally describing them. We will also examine other forms they can take.
As mentioned earlier, a lambda expression is essentially an anonymous function. They can be passed to another function or method, returned from a function or a method, and assigned to variables.
A lambda expression consists of an optional parameter list, followed by the lambda operator, and then a body. The lambda operator is a dash followed by the greater than symbol. The body of a lambda expression may be one or more statements and may optionally return a value.
Let's examine several variations of a simple lambda expression. A single value is passed to the function. This value is incremented and then returned. Several equivalent variations of this function are illustrated in the following table:
Variation |
Comment |
---|---|
|
The simplest form of the function |
|