16

I have recently heard people talk about code being "lambda". I have never heard of this phrase before. What does it mean?

Oliver Moran
  • 279
  • 1
  • 2
  • 5

2 Answers2

21

Lambda expressions are either an abstraction (sometimes referred to as anonymous function), an application or a variable (most languages also add constants to this list). Lambda terms are not necessarily functions, and not necessarily passed as parameters, though this is a common practice.

A common example of lambda expressions in C#

For example:

List<int> items = new List<int>();
items.add(1);
items.add(2);
items.add(1);
items.add(3);

int CountofOnes = items.FindAll(item => item == 1).Count();

Console.Out.WriteLine(CountofOnes);

will output: 2

In this code, I pass a lambda construction to the FindAll function of .NET's List object.

items.FindAll(item => item == 1)

The lambda in this call executes a simple equation and returns a boolean, telling FindAll what to do.

Timothy Groote
  • 655
  • 3
  • 9
1

Lambda usually refers to a function expression in a functional programming context.

This is a lambda expression in python:

lambda x: x + 1

Represents a function that increments its parameter x by 1.