Skip to content

Instantly share code, notes, and snippets.

@swavkulinski
Last active May 23, 2023 08:31
Show Gist options
  • Save swavkulinski/d1faa90bd99238280a9b98189c5e52c0 to your computer and use it in GitHub Desktop.
Save swavkulinski/d1faa90bd99238280a9b98189c5e52c0 to your computer and use it in GitHub Desktop.
Records: unboxing & Fibonacci example
void main() {
var result = <int>[];
for (var (int x,int y) = (0,1); y < 100; (x+=y,y+=x)){
result.add(x);
result.add(y);
}
print (result);
}
// Method returning a Record of int and String
(int, String) calculateResult() => (10, "comment");
void main() {
// Standard unboxing
final result = calculateResult();
print ('result.\$1 : ${result.$1}');
print ('result.\$2 : ${result.$2}');
// Unboxing to variables
final (value, comment) = calculateResult();
print ('value: $value');
print ('comment: $comment');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment