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 mappedBy(Iterable source, mapper(source)) { |
11 List result = new List(); | 11 List result = new List(); |
12 if (source is List) { | 12 if (source is List) { |
13 List list = source; // TODO: shouldn't need this | 13 List list = source; // TODO: shouldn't need this |
14 result.length = list.length; | 14 result.length = list.length; |
15 for (int i = 0; i < list.length; i++) { | 15 for (int i = 0; i < list.length; i++) { |
16 result[i] = mapper(list[i]); | 16 result[i] = mapper(list[i]); |
17 } | 17 } |
18 } else { | 18 } else { |
19 for (final item in source) { | 19 for (final item in source) { |
20 result.add(mapper(item)); | 20 result.add(mapper(item)); |
(...skipping 25 matching lines...) Expand all Loading... |
46 } | 46 } |
47 result.add(mapper(x.current, y.current)); | 47 result.add(mapper(x.current, y.current)); |
48 } | 48 } |
49 if (y.moveNext()) { | 49 if (y.moveNext()) { |
50 throw new ArgumentError(); | 50 throw new ArgumentError(); |
51 } | 51 } |
52 return result; | 52 return result; |
53 } | 53 } |
54 | 54 |
55 | 55 |
OLD | NEW |