Elm Language Functions and Partial Application Lambda expressions


Example

Elm has a special syntax for lambda expressions or anonymous functions:

\arguments -> returnedValue

For example, as seen in List.filter:

> List.filter (\num -> num > 1) [1,2,3]
[2,3] : List number

More to the depth, a backward slash, \, is used to mark the beginning of lambda expression, and the arrow, ->, is used to delimit arguments from the function body. If there are more arguments, they get separated by a space:

normalFunction x y = x + y
-- is equivalent to
lambdaFunction = \x y -> x + y

> normalFunction 1 2
3 : number

> lambdaFunction 1 2
3 : number