
In short, a lambda is just an anonymous and inline function. I will illustrate it intuitively step by step in simple and readable python codes. RESULT: įor a person without a comp-sci background, what is a lambda in the world of Computer Science? Operator Methods reverseOrder = coffee.sorted(by: >)

$0 and $1 are closure’s first and second String arguments.ħ.

Swift func adder(x: Int) -> (Int) -> Int ) Var add6 = adder(6) // Using implicit typing (int x) => (int y) => x + y // `int` declarations optional JavaScript (ES6) const adder = x => y => x + y This is a simple example, but it should convey the power lambdas and closures have. That anonymous function allows you to create functions from functions. With that power you can do things like this.Īs you can see from the snippet of Python, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. It also provides a nice way to write closures.

Why is this cool? It allows you to write quick throw away functions without naming them. Lambda comes from the Lambda Calculus and refers to anonymous functions in programming.
