Last active
May 23, 2023 08:31
-
-
Save swavkulinski/d1faa90bd99238280a9b98189c5e52c0 to your computer and use it in GitHub Desktop.
Records: unboxing & Fibonacci example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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