⚡ Lambda Expressions¶
Lambda expressions are small, anonymous functions written in a single line. They are commonly used for short transformations and callbacks.
✅ Syntax¶
Examples:
✅ When to Use¶
- Short, simple logic
- Passed to higher-order functions (e.g.,
map,filter,sorted) - Inline callbacks
✅ Common Examples¶
Sorting with a key¶
Filtering with a lambda¶
⚠️ Keep It Readable¶
If the logic gets complex, use a named function instead. Readability matters more than brevity.
🔍 Key Takeaways¶
- Lambda functions are anonymous and single-expression.
- Best for short, simple operations.
- Often used with higher-order functions.