In my quest to understand the very odd looking \' => \' operator, I have found a good place to start, and the author is very concise and clear:
As others have said, a lambda expression is a notation for a function. It binds the free variables in the right-hand-side of the expression to the parameters on the left.
a => a + 1
creates a function that binds the free variable a in the expression (a + 1) to the first parameter of a function and returns that function.
One case where Lambdas are extremely useful is when you use them to work with list structures. The System.Linq.Enumerable class provides a lot of useful functions that allow you to work with Lambda expressions and objects implementing IEnumerable. For example Enumerable.Where can be used to filter a list:
List<string> fruits = new List<string> {
"apple", "passionfruit", "banana", "mango",
"orange", "blueberry", "grape", "strawberry" };
IEnumerable<string> shortFruits = fruits.Where(fruit => fruit.Length < 6);
foreach (string fruit in shortFruits) {
Console.WriteLine(fruit);
}
The output will be "apple, mango, grape".
Try to understand what's going on here: the expression fruit => fruit.Length < 6 creates a function which return true if the parameter's Length property is less than 6.
Enumerable.Where loops over the List and creates a new List which contains only those elements for which the supplied function returns true. This saves you to write code that iterates over the List, checks a predicate for each element and does something.
Lambda calculus is common in many programming languages. They're also called anonymous functions in some languages. Though different languages have different syntax for lambda, the principle is the same, and their various parts are usually identical.
Perhaps the most famous one is Javascript's anonymous functions.
lol = function() {laugh()}
# is equivalent to
function lol() {laugh()}
What's the difference? Well, sometimes you don't want to go through the trouble of creating a function just to pass it somewhere once and then never again.
window.onload = function() {laugh()}
# is way easier than
function lol() {laugh()}
window.onload = lol
You can see the wikipedia article for indept information or you can skip directly to Lambda in programming in the same article.
My tip for understanding the basics of lambdas is two fold.
Firstly I recommend learning about functional programming. Haskell is a good language to start off with in that respect. The book I am using, and getting a lot out of, is Programming in Haskell by Graham Hutton. This gives a good grounding in Haskell and includes explanations of lambdas.
From there I think you should view Erik Meijer's lectures on Functional Programming as they give a great intro to functional programming as well, also using Haskell, and crossing over into C#.
Once you've taken in all that you should be well on the way to understanding lambdas.
I know this is kinda old but i came here trying to make sense of all this lambda stuff. By the time i finished pouring over all the answers and comments, i had a better understnading of lambda and thought i should just add this simple answer(from a learner's perspective to learners):
Dont confuse a => a + 1
as meaning add 1 to a and return the result to a. (this is most likely a source of confusion for beginners.
Instead see it like this: a is the input parameter into a function(unnamed function) and a + 1 is the statement(s) in the function(unnamed function constructed 'on the fly').
Hope this helps :)