Lambda Expressions: The fun Keyword (F#)
The fun keyword is used to define a lambda expression, that is, an anonymous function.
The parameter-list consists of names and, optionally, types of parameters. Examples of valid parameter lists include the following:
The parameter-list can be composed of any F# patterns. For a full list of possible patterns, see Pattern Matching (F#).
The expression is the body of the function, the last expression of which generates a return value. Examples of valid lambda expressions include the following:
Lambda expressions are especially useful when you want to perform operations on a list or other collection and want to avoid the extra work of defining a function. Many F# library functions take function values as arguments, and it can be especially convenient to use a lambda expression in those cases. The following code applies a lambda expression to elements of a list. In this case, the anonymous function adds 1 to every element of a list.