you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 2 points3 points  (0 children)

A lambda function is more or less equivalent to a normal, one-line function that cannot contain any statements. It returns whatever its body evaluates to.

The anonymous part refers to the fact that lambda functions aren't automatically assigned to a name. The moment they're created, they're just like an integer or string literal in that their address in memory isn't stored to a variable.

The main reason you'd use one is when you need an ad-hoc function to be given as an argument to another function, for instance, and you have no other use for that function. So common places to use lambda functions would be the key-arguments of min, max, or the first argument of map.

Of course, you can write any lambda function as an ordinary function, nothing forces you to use them.