Lambda Expressions

 
 
 

Parts of the Showcase API rely on the usage of lambda expressions for call-backs. A lambda expression is a kind of function which has no name, also called an anonymous function. It can be assigned to a variable, or passed to a function. Lambda expressions can refer to variables in their surrounding context (i.e. scope).

The following is a simple example of a lambda-expression assigned to a variable:

>>> inc = lambda x: return x + 1
>>> print inc(41)
42

The following is an example of a lambda-expression passed as an argument to a function:

>>> xs = [2, 3, 4, 5, 6, 7] 
>>> print filter(lambda x: x % 2 == 0, xs)
[2, 4, 6]