Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: pkg/polymer_expressions/lib/src/globals.dart

Issue 71353012: Make sure 'enumerate' changes when the underlying collection changes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/polymer_expressions/lib/eval.dart ('k') | pkg/polymer_expressions/test/globals_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'package:observe/observe.dart' show reflectable;
15 15
16 /** 16 /**
17 * 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
18 * element of [iterable] and its index. 18 * element of [iterable] and its index.
19 */ 19 */
20 Iterable<IndexedValue> enumerate(Iterable iterable) => 20 Iterable<IndexedValue> enumerate(Iterable iterable) =>
21 new EnumerateIterable(iterable); 21 new EnumerateIterable(iterable);
22 22
23 @reflectable class IndexedValue<V> { 23 @reflectable class IndexedValue<V> {
24 final int index; 24 final int index;
25 final V value; 25 final V value;
26 26
27 operator==(o) => o is IndexedValue && o.index == index && o.value == value;
Jennifer Messerly 2013/11/14 02:50:49 wonder if we should upstream this (if you haven't
Siggi Cherem (dart-lang) 2013/11/14 17:56:11 good idea. Will do
28 int get hashCode => value.hashCode;
29 String toString() => '($index, $value)';
30
27 IndexedValue(this.index, this.value); 31 IndexedValue(this.index, this.value);
28 } 32 }
29 33
30 /** 34 /**
31 * An [Iterable] of [IndexedValue]s where the nth value holds the nth 35 * An [Iterable] of [IndexedValue]s where the nth value holds the nth
32 * element of [iterable] and its index. See [enumerate]. 36 * element of [iterable] and its index. See [enumerate].
33 */ 37 */
34 // This was inspired by MappedIterable internal to Dart collections. 38 // This was inspired by MappedIterable internal to Dart collections.
35 class EnumerateIterable<V> extends IterableBase<IndexedValue<V>> { 39 class EnumerateIterable<V> extends IterableBase<IndexedValue<V>> {
36 final Iterable<V> _iterable; 40 final Iterable<V> _iterable;
(...skipping 27 matching lines...) Expand all
64 68
65 bool moveNext() { 69 bool moveNext() {
66 if (_iterator.moveNext()) { 70 if (_iterator.moveNext()) {
67 _current = new IndexedValue(_index++, _iterator.current); 71 _current = new IndexedValue(_index++, _iterator.current);
68 return true; 72 return true;
69 } 73 }
70 _current = null; 74 _current = null;
71 return false; 75 return false;
72 } 76 }
73 } 77 }
OLDNEW
« no previous file with comments | « pkg/polymer_expressions/lib/eval.dart ('k') | pkg/polymer_expressions/test/globals_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698