OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Collection<T> supports most of the ES 5 Array methods, but it's missing | 5 // Collection<T> supports most of the ES 5 Array methods, but it's missing |
6 // map and reduce. | 6 // map and reduce. |
7 | 7 |
8 // TODO(jmesserly): we might want a version of this that return an iterable, | 8 // TODO(jmesserly): we might want a version of this that return an iterable, |
9 // however JS, Python and Ruby versions are all eager. | 9 // however JS, Python and Ruby versions are all eager. |
10 List map(Iterable source, mapper(source)) { | 10 List map(Iterable source, mapper(source)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 if (x.hasNext() || y.hasNext()) { | 46 if (x.hasNext() || y.hasNext()) { |
47 throw new IllegalArgumentException(); | 47 throw new IllegalArgumentException(); |
48 } | 48 } |
49 return result; | 49 return result; |
50 } | 50 } |
51 | 51 |
52 /** Sorts the map by the key. */ | 52 /** Sorts the map by the key. */ |
53 List orderValuesByKeys(Map map) { | 53 List orderValuesByKeys(Map map) { |
54 // TODO(jmesserly): it'd be nice to have SortedMap in corelib. | 54 // TODO(jmesserly): it'd be nice to have SortedMap in corelib. |
55 List keys = map.getKeys(); | 55 final keys = map.getKeys(); |
56 keys.sort((x, y) => x.compareTo(y)); | 56 keys.sort((x, y) => x.compareTo(y)); |
57 final values = []; | 57 final values = []; |
58 for (var k in keys) { | 58 for (var k in keys) { |
59 values.add(map[k]); | 59 values.add(map[k]); |
60 } | 60 } |
61 return values; | 61 return values; |
62 } | 62 } |
63 | 63 |
64 /** True if this is a triple quoted Dart string literal. */ | 64 /** True if this is a triple quoted Dart string literal. */ |
65 bool isMultilineString(String text) { | 65 bool isMultilineString(String text) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 final int length; | 126 final int length; |
127 int _index = 0; | 127 int _index = 0; |
128 FixedIterator(this.value, this.length); | 128 FixedIterator(this.value, this.length); |
129 | 129 |
130 bool hasNext() => _index < length; | 130 bool hasNext() => _index < length; |
131 E next() { | 131 E next() { |
132 _index++; | 132 _index++; |
133 return value; | 133 return value; |
134 } | 134 } |
135 } | 135 } |
OLD | NEW |