Lambda Expressions
A few years ago a conference organizer asked if I’d like to talk about Lambada expressions. Dancing is a form of expression, but I’m far from being qualified to talk about it—I chose lambda expressions instead. Lambdas are also a form of expression—they’re concise, expressive, and elegant.
Lambdas are short functions that are used as arguments to higher-order functions. Rather than passing data to functions, we can use lambdas to pass a piece of executable code to functions. Instead of using data to make decisions or perform calculations, the higher-order functions can rely on the lambdas to make decisions or perform calculations. In essence, it’s like instead of giving someone a fish, you’re giving them a fishing lesson. Let’s dive into lambdas.
Structure of lambdas
A lambda expression is a function with no name whose return type is inferred. Generally a function has four parts: name, return type, parameters list, and body. Lambdas carry over only the most essential parts of a function—the ...