OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Contains functions that are included by default in [PolymerExpressions]. | 6 * Contains functions that are included by default in [PolymerExpressions]. |
7 * | 7 * |
8 * - [enumerate]: a convenient way to iterate over items and the indexes. | 8 * - [enumerate]: a convenient way to iterate over items and the indexes. |
9 */ | 9 */ |
10 // Code from https://github.com/google/quiver-dart/commit/52edc4baf37e99ff6a8f99
c648b29b135fc0b880 | 10 // Code from https://github.com/google/quiver-dart/commit/52edc4baf37e99ff6a8f99
c648b29b135fc0b880 |
11 library polymer_expressions.src.globals; | 11 library polymer_expressions.src.globals; |
12 | 12 |
13 import 'dart:collection'; | 13 import 'dart:collection'; |
| 14 import 'package:observe/observe.dart' show reflectable; |
14 | 15 |
15 /** | 16 /** |
16 * Returns an [Iterable] of [IndexedValue]s where the nth value holds the nth | 17 * Returns an [Iterable] of [IndexedValue]s where the nth value holds the nth |
17 * element of [iterable] and its index. | 18 * element of [iterable] and its index. |
18 */ | 19 */ |
19 Iterable<IndexedValue> enumerate(Iterable iterable) => | 20 Iterable<IndexedValue> enumerate(Iterable iterable) => |
20 new EnumerateIterable(iterable); | 21 new EnumerateIterable(iterable); |
21 | 22 |
22 class IndexedValue<V> { | 23 @reflectable class IndexedValue<V> { |
23 final int index; | 24 final int index; |
24 final V value; | 25 final V value; |
25 | 26 |
26 IndexedValue(this.index, this.value); | 27 IndexedValue(this.index, this.value); |
27 } | 28 } |
28 | 29 |
29 /** | 30 /** |
30 * An [Iterable] of [IndexedValue]s where the nth value holds the nth | 31 * An [Iterable] of [IndexedValue]s where the nth value holds the nth |
31 * element of [iterable] and its index. See [enumerate]. | 32 * element of [iterable] and its index. See [enumerate]. |
32 */ | 33 */ |
(...skipping 30 matching lines...) Expand all Loading... |
63 | 64 |
64 bool moveNext() { | 65 bool moveNext() { |
65 if (_iterator.moveNext()) { | 66 if (_iterator.moveNext()) { |
66 _current = new IndexedValue(_index++, _iterator.current); | 67 _current = new IndexedValue(_index++, _iterator.current); |
67 return true; | 68 return true; |
68 } | 69 } |
69 _current = null; | 70 _current = null; |
70 return false; | 71 return false; |
71 } | 72 } |
72 } | 73 } |
OLD | NEW |