LINQ, Lambda expressions and maths

One of the features that enables LINQ to work are the implementation of Lambda expressions. Lambda expressions are basically another way of representing a function, and are used in LINQ to pass function pointers/delegates around without the verbosity of declaring function blocks. For example:

public List GetFirstAiders() {
  List employees = getEmployees();
  return employees.FindAll(IsFirstAider);
}
public bool IsFirstAider(Employee employee) {
  return employee.IsFirstAider;
}

Using lambda expressions this becomes:

public List GetFirstAiders() {
  List employees = getEmployees();
  return employees.FindAll(e => e.IsFirstAider);
}

The (e => e.IsFirstAider) is the lambda expression that represents the old bool IsFirstAider(Employee) method. The types used in the function expressed are not explicitly mentioned, but are instead implied by the List method signature.

Anyway, the initial point of this post was to mention that Wikipedia has information on the mathematical background of lambda calculus.

Comments