Lambda is a short and concise manner to represent small functions.
Lambda functions are also called Arrow functions.
But here remember that by using Lambda function’s syntax you can only return one expression. It must be only one line expression. Just like normal function lambda function cannot have a block of code to execute.
In short, if your function has only one expression to return then to quickly represent it in just one line you can use lambda function.
Syntax
return_type function_name(arguments) => expression;
- Here also note that we don’t need a return statement explicitly.
Program
int ShowSum(int numOne, int numTwo) => numOne + numTwo;
main() {
print(ShowSum(10, 20));
}
Output
30
That’s it for lambda functions guys. Please play around with this concept for some time. Also, Feel free to let me know if I miss something. Till Then keep Loving, Keep Coding. And I’ll surely catch you up in next article.
Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.
Learn more about Dart and Flutter
- List in Dart
- Abstract class and Abstract Methods in Dart
- Interface in Dart
- Constructors in Dart
- Arrow Function in Dart
- User Defined Function in Dart
- Functions in Dart
- Switch case in Dart
- Conditionals in Dart
- Operators in Dart
- Keywords in Dart
- Variables in Dart
- Data Types in Dart
Top comments (0)