Lambda functions are a short and simple way to express tiny functions. Lambda functions are also known as arrow functions. Like any other function, a Lambda function cannot execute a block of code.
return_type func_name(parameters)=> expression;
Note: You can only return one expression when using Lambda function syntax, which has to be a single-line expression.
// Using lambda function int addNum(int a, int b) => a + b; main() { print(addNum(15, 7)); }
Note: A return statement isn’t explicitly required.
void main() { displayMsg(); } displayMsg()=> print("This is a shot on Lambda functions in Dart programming");
// Using lambda function String showData(String a, String b) => a + b; main() { print(showData("Educative ", "shot")); }
Finally, if a function only returns one expression, you may use the Lambda function to represent it in only one line.
RELATED TAGS
CONTRIBUTOR
View all Courses