| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 * Base implementations of [Set]. | 6 * Base implementations of [Set]. |
| 7 */ | 7 */ |
| 8 part of dart.collection; | 8 part of dart.collection; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 List<E> toList({bool growable: true}) { | 115 List<E> toList({bool growable: true}) { |
| 116 List<E> result = | 116 List<E> result = |
| 117 growable ? (new List<E>()..length = length) : new List<E>(length); | 117 growable ? (new List<E>()..length = length) : new List<E>(length); |
| 118 int i = 0; | 118 int i = 0; |
| 119 for (E element in this) result[i++] = element; | 119 for (E element in this) result[i++] = element; |
| 120 return result; | 120 return result; |
| 121 } | 121 } |
| 122 | 122 |
| 123 Iterable<T> map<T>(T f(E element)) => new EfficientLengthMappedIterable<E, T>( | 123 Iterable<T> map<T>(T f(E element)) => |
| 124 this, f); | 124 new EfficientLengthMappedIterable<E, T>(this, f); |
| 125 | 125 |
| 126 E get single { | 126 E get single { |
| 127 if (length > 1) throw IterableElementError.tooMany(); | 127 if (length > 1) throw IterableElementError.tooMany(); |
| 128 Iterator<E> it = iterator; | 128 Iterator<E> it = iterator; |
| 129 if (!it.moveNext()) throw IterableElementError.noElement(); | 129 if (!it.moveNext()) throw IterableElementError.noElement(); |
| 130 E result = it.current; | 130 E result = it.current; |
| 131 return result; | 131 return result; |
| 132 } | 132 } |
| 133 | 133 |
| 134 String toString() => IterableBase.iterableToFullString(this, '{', '}'); | 134 String toString() => IterableBase.iterableToFullString(this, '{', '}'); |
| 135 | 135 |
| 136 // Copied from IterableMixin. | 136 // Copied from IterableMixin. |
| 137 // Should be inherited if we had multi-level mixins. | 137 // Should be inherited if we had multi-level mixins. |
| 138 | 138 |
| 139 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); | 139 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); |
| 140 | 140 |
| 141 Iterable<T> | 141 Iterable<T> expand<T>(Iterable<T> f(E element)) => |
| 142 expand<T>(Iterable<T> f(E element)) => new ExpandIterable<E, T>(this, f); | 142 new ExpandIterable<E, T>(this, f); |
| 143 | 143 |
| 144 void forEach(void f(E element)) { | 144 void forEach(void f(E element)) { |
| 145 for (E element in this) f(element); | 145 for (E element in this) f(element); |
| 146 } | 146 } |
| 147 | 147 |
| 148 E reduce(E combine(E value, E element)) { | 148 E reduce(E combine(E value, E element)) { |
| 149 Iterator<E> iterator = this.iterator; | 149 Iterator<E> iterator = this.iterator; |
| 150 if (!iterator.moveNext()) { | 150 if (!iterator.moveNext()) { |
| 151 throw IterableElementError.noElement(); | 151 throw IterableElementError.noElement(); |
| 152 } | 152 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 abstract class SetBase<E> extends SetMixin<E> { | 301 abstract class SetBase<E> extends SetMixin<E> { |
| 302 /** | 302 /** |
| 303 * Convert a `Set` to a string as `{each, element, as, string}`. | 303 * Convert a `Set` to a string as `{each, element, as, string}`. |
| 304 * | 304 * |
| 305 * Handles circular references where converting one of the elements | 305 * Handles circular references where converting one of the elements |
| 306 * to a string ends up converting [set] to a string again. | 306 * to a string ends up converting [set] to a string again. |
| 307 */ | 307 */ |
| 308 static String setToString(Set set) => | 308 static String setToString(Set set) => |
| 309 IterableBase.iterableToFullString(set, '{', '}'); | 309 IterableBase.iterableToFullString(set, '{', '}'); |
| 310 } | 310 } |
| OLD | NEW |