OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 class A extends Iterable { |
| 6 int count; |
| 7 A(this.count); |
| 8 |
| 9 Iterator get iterator { |
| 10 return new AIterator(count); |
| 11 } |
| 12 } |
| 13 |
| 14 class AIterator implements Iterator { |
| 15 int _count; |
| 16 int _current; |
| 17 |
| 18 AIterator(this._count); |
| 19 |
| 20 bool moveNext() { |
| 21 if (_count > 0) { |
| 22 _current = _count; |
| 23 _count--; |
| 24 return true; |
| 25 } |
| 26 _current = null; |
| 27 return false; |
| 28 } |
| 29 |
| 30 get current => _current; |
| 31 } |
| 32 |
| 33 main() { |
| 34 var a = new A(10); |
| 35 Expect.equals(10, a.length); |
| 36 a = new A(0); |
| 37 Expect.equals(0, a.length); |
| 38 a = new A(5); |
| 39 Expect.equals(5, a.mappedBy((e) => e + 1).length); |
| 40 Expect.equals(3, a.where((e) => e >= 3).length); |
| 41 } |
OLD | NEW |