| 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 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 List zip(Iterable left, Iterable right, mapper(left, right)) { | 39 List zip(Iterable left, Iterable right, mapper(left, right)) { |
| 40 List result = new List(); | 40 List result = new List(); |
| 41 var x = left.iterator(); | 41 var x = left.iterator(); |
| 42 var y = right.iterator(); | 42 var y = right.iterator(); |
| 43 while (x.hasNext() && y.hasNext()) { | 43 while (x.hasNext() && y.hasNext()) { |
| 44 result.add(mapper(x.next(), y.next())); | 44 result.add(mapper(x.next(), y.next())); |
| 45 } | 45 } |
| 46 if (x.hasNext() || y.hasNext()) { | 46 if (x.hasNext() || y.hasNext()) { |
| 47 throw new IllegalArgumentException(); | 47 throw new ArgumentError(); |
| 48 } | 48 } |
| 49 return result; | 49 return result; |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| OLD | NEW |