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

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

Issue 26318004: fix dart2js warnings in polymer_expressions pkg (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months 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
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 14
15 /** 15 /**
16 * Returns an [Iterable] of [IndexedValue]s where the nth value holds the nth 16 * Returns an [Iterable] of [IndexedValue]s where the nth value holds the nth
17 * element of [iterable] and its index. 17 * element of [iterable] and its index.
18 */ 18 */
19 Iterable<IndexedValue> enumerate(Iterable iterable) => 19 Iterable<IndexedValue> enumerate(Iterable iterable) =>
20 new EnumerateIterable(iterable); 20 new EnumerateIterable(iterable);
21 21
22 class IndexedValue<V> { 22 class IndexedValue<V> {
23 final int index; 23 final int index;
24 final V value; 24 final V value;
25 25
26 IndexedValue(this.index, this.value); 26 IndexedValue(this.index, this.value);
27 } 27 }
28 28
29
30 /** 29 /**
31 * An [Iterable] of [IndexedValue]s where the nth value holds the nth 30 * An [Iterable] of [IndexedValue]s where the nth value holds the nth
32 * element of [iterable] and its index. See [enumerate]. 31 * element of [iterable] and its index. See [enumerate].
33 */ 32 */
34 // This was inspired by MappedIterable internal to Dart collections. 33 // This was inspired by MappedIterable internal to Dart collections.
35 class EnumerateIterable<V> extends IterableBase<IndexedValue<V>> { 34 class EnumerateIterable<V> extends IterableBase<IndexedValue<V>> {
36 final Iterable<V> _iterable; 35 final Iterable<V> _iterable;
37 36
38 EnumerateIterable(this._iterable); 37 EnumerateIterable(this._iterable);
39 38
40 Iterator<V> get iterator => new EnumerateIterator<V>(_iterable.iterator); 39 Iterator<IndexedValue<V>> get iterator =>
40 new EnumerateIterator<V>(_iterable.iterator);
41 41
42 // Length related functions are independent of the mapping. 42 // Length related functions are independent of the mapping.
43 int get length => _iterable.length; 43 int get length => _iterable.length;
44 bool get isEmpty => _iterable.isEmpty; 44 bool get isEmpty => _iterable.isEmpty;
45 45
46 // Index based lookup can be done before transforming. 46 // Index based lookup can be done before transforming.
47 IndexedValue<V> get first => new IndexedValue<V>(0, _iterable.first); 47 IndexedValue<V> get first => new IndexedValue<V>(0, _iterable.first);
48 IndexedValue<V> get last => new IndexedValue<V>(length - 1, _iterable.last); 48 IndexedValue<V> get last => new IndexedValue<V>(length - 1, _iterable.last);
49 IndexedValue<V> get single => new IndexedValue<V>(0, _iterable.single); 49 IndexedValue<V> get single => new IndexedValue<V>(0, _iterable.single);
50 IndexedValue<V> elementAt(int index) => 50 IndexedValue<V> elementAt(int index) =>
51 new IndexedValue<V>(index, _iterable.elementAt(index)); 51 new IndexedValue<V>(index, _iterable.elementAt(index));
52 } 52 }
53 53
54 /** The [Iterator] returned by [EnumerateIterable.iterator]. */ 54 /** The [Iterator] returned by [EnumerateIterable.iterator]. */
55 class EnumerateIterator<V> extends Iterator<IndexedValue<V>> { 55 class EnumerateIterator<V> extends Iterator<IndexedValue<V>> {
56 final Iterator<IndexedValue<V>> _iterator; 56 final Iterator<V> _iterator;
57 int _index = 0; 57 int _index = 0;
58 IndexedValue<V> _current; 58 IndexedValue<V> _current;
59 59
60 EnumerateIterator(this._iterator); 60 EnumerateIterator(this._iterator);
61 61
62 IndexedValue<V> get current => _current; 62 IndexedValue<V> get current => _current;
63 63
64 bool moveNext() { 64 bool moveNext() {
65 if (_iterator.moveNext()) { 65 if (_iterator.moveNext()) {
66 _current = new IndexedValue(_index++, _iterator.current); 66 _current = new IndexedValue(_index++, _iterator.current);
67 return true; 67 return true;
68 } 68 }
69 _current = null; 69 _current = null;
70 return false; 70 return false;
71 } 71 }
72 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698