Dart by Example: Iterators

  1. main() {
  2. var iter = [1,5,10].iterator;
  3. while(iter.moveNext()) {
  4. print(iter.current);
  5. }
  6. var iterable = new Iterable.generate(3);
  7. var iter2 = iterable.map((n) => n*2).iterator;
  8. while(iter2.moveNext()) {
  9. print(iter2.current);
  10. }
  11. }
  12.  
  1. $ dart iterators.dart
  2. 1
  3. 5
  4. 10
  5. 0
  6. 2
  7. 4

by @jryanio | source | license