Created
April 9, 2022 18:33
-
-
Save hawkkiller/7e921d40dc63b933826c909f695b6fe4 to your computer and use it in GitHub Desktop.
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
import 'package:meta/meta.dart'; | |
void main() { | |
// iterates only first element. | |
gen().first; | |
print('Iterated first item because of first\n'); | |
// iterates each element | |
gen().toList(); | |
print('Iterated List\n'); | |
gen().last; | |
print('Iterated each item because of last\n'); | |
// create lazy iterable | |
final lazy = gen(); | |
// create iterator | |
final iterator = lazy.iterator; | |
while (iterator.moveNext()) { | |
print('current value -> ${iterator.current}'); | |
iterator.moveNext(); | |
print('move next'); | |
} | |
print('Iterated each item\n'); | |
} | |
// creates sequence of ints | |
Iterable<int> gen() sync* { | |
for (int i = 0; i < 5; i++) { | |
print('iterate element $i'); | |
yield i; | |
} | |
} | |
// Michael Lazebny |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment