DEV Community

Cover image for Lambda Functions in Dart
Jay Tillu
Jay Tillu

Posted on • Edited on

Lambda Functions in Dart

  • 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;
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

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

Follow me for more such content

Top comments (0)