Functions and Records
Arrow Functions
=> Shorthand
When a function's body is a single expression, => is shorthand for { return expr; }. The block form and the arrow form behave identically; arrow is just more concise.
Program
Play the program to call a block-body and an arrow-body version of the same idea.
arrow_functions.dart
int squareBlock(int n) {
return n * n;
}
int squareArrow(int n) => n * n;
void main() {
var a = squareBlock(5);
var b = squareArrow(6);
print('$a $b');
}
arrow body
`fn(x) => expr` is shorthand for `{ return expr; }` when the body is one expression.
implicit return
There is no `return` keyword in an arrow body; the expression's value is returned.
equivalent semantics
Block-body and arrow-body produce the same call result; arrow is just terser.