OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Contains functions that are included by default in [PolymerExpressions]. |
| 7 * |
| 8 * - [enumerate]: a convenient way to iterate over items and the indexes. |
| 9 */ |
| 10 library polymer_expressions.src.globals; |
| 11 |
| 12 /** |
| 13 * Returns an [Iterable] of [IndexedValue]s where the nth value holds the nth |
| 14 * element of [iterable] and its index. |
| 15 */ |
| 16 Iterable<IndexedValue> enumerate(Iterable iterable) { |
| 17 int i = 0; |
| 18 return iterable.map((e) => new IndexedValue(i++, e)); |
| 19 } |
| 20 |
| 21 class IndexedValue<V> { |
| 22 final int index; |
| 23 final V value; |
| 24 |
| 25 IndexedValue(this.index, this.value); |
| 26 } |
OLD | NEW |