Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you read lambda expressions?

Tags:

c#

.net

lambda

I've been trying figure out why lambda expressions don't feel intuitive to me yet. I suspect part of it may be because when I skim code, I sometimes internally translate it to my native language for my own clarity. For example:

endDate.Value = someNullableDate ?? (object)DBNull.Value;
// I could read as:
set endDate to someNullableDate or, if null, to (object)dbNull

An example from another language:

for(int count = 0; count >= 42; count++) {
    cout << "Count is " << count << endl;
}
// May read as:
from an integer "count" as zero to 42 inclusive, display "Count is " and then the integer.

So how would one read the lambda expression in:

var myList = new List<String>(/* various string values */);
var foo = myList.Select(s => s.Trim()).ToList(); //?
like image 981
Charles Burns Avatar asked Jun 20 '11 14:06

Charles Burns


People also ask

What does => mean in lambda?

In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.

What does => mean in Linq?

the operator => has nothing to do with linq - it's a lambda expression. It's used to create anonymous functions, so you don't need to create a full function for every small thing.

How lambda is represented?

Lambda (uppercase/lowercase Λ λ) is a letter of the Greek alphabet. It is used to represent the "l" sound in Ancient and Modern Greek. In the system of Greek numerals, it has a value of 30.

What language is λ?

Overview of Lambda Programming Languages Lambda allows developers to implement custom runtimes 2, but also offer a list of execution environments available out-of-the-box. Implementing applications in these 'default' environments are the ones this guide is going to cover.


1 Answers

I would read this as:

Select each item individually from myList into a variable s, using s, apply a Trim() on it and once done with all items in myList, convert the whole thing to a list.

like image 110
Jamie Dixon Avatar answered Oct 10 '22 08:10

Jamie Dixon