The Why of Lambdas
You may be wondering what need, other than the flowering of geekly expressionism, the lambda serves. Let’s examine this question in terms of four qualities: proximity, brevity, efficiency, and capability.
Many programmers feel that it is useful to locate definitions close to where they are used. That way, you don’t have to scan through pages of source code to find, say, what the third argument to a count_if() function call accomplishes. Also if you need to modify the code, all the components are close at hand. And if you cut and paste the code for use elsewhere, again all the components are at hand. From this standpoint, lambdas are ideal because the definition is at the point of usage. Functions are worst because functions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access