Lambda Functions

► Understanding Lambda Functions

Lambda functions are small, anonymous functions defined in a single line. They can have any number of parameters but only one expression. Lambda functions are useful for short, simple operations that you need temporarily.

► Real-World Analogy

Think of lambda functions like sticky notes with quick instructions:
» A full function is like a detailed instruction manual with a title and multiple steps
» A lambda function is like a quick note: “Add 5” or “Multiply by 2”
» You use sticky notes for simple, one-time reminders
» You don’t need to give them formal names
» Perfect for quick tasks you won’t reuse elsewhere

► Key Concepts

✓ Anonymous functions: No name required
✓ Single expression: Can only contain one expression
✓ Inline definition: Defined where they’re used
✓ Return implicit: Automatically returns expression result
✓ Common with map(), filter(), sort(): Often used as arguments

■ Code Examples