OLD | NEW |
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 part of dart.collection; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * Abstract implementation of a list. | 8 * Abstract implementation of a list. |
9 * | 9 * |
10 * `ListBase` can be used as a base class for implementing the `List` interface. | 10 * `ListBase` can be used as a base class for implementing the `List` interface. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 168 } |
169 | 169 |
170 String join([String separator = ""]) { | 170 String join([String separator = ""]) { |
171 if (length == 0) return ""; | 171 if (length == 0) return ""; |
172 StringBuffer buffer = new StringBuffer()..writeAll(this, separator); | 172 StringBuffer buffer = new StringBuffer()..writeAll(this, separator); |
173 return buffer.toString(); | 173 return buffer.toString(); |
174 } | 174 } |
175 | 175 |
176 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); | 176 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); |
177 | 177 |
178 Iterable map(f(E element)) => new MappedListIterable(this, f); | 178 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E element)) => new MappedListIterable<E, d
ynamic/*=T*/>(this, f); |
179 | 179 |
180 Iterable expand(Iterable f(E element)) => | 180 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(E element)) => |
181 new ExpandIterable<E, dynamic>(this, f); | 181 new ExpandIterable<E, dynamic/*=T*/>(this, f); |
182 | 182 |
183 E reduce(E combine(E previousValue, E element)) { | 183 E reduce(E combine(E previousValue, E element)) { |
184 int length = this.length; | 184 int length = this.length; |
185 if (length == 0) throw IterableElementError.noElement(); | 185 if (length == 0) throw IterableElementError.noElement(); |
186 E value = this[0]; | 186 E value = this[0]; |
187 for (int i = 1; i < length; i++) { | 187 for (int i = 1; i < length; i++) { |
188 value = combine(value, this[i]); | 188 value = combine(value, this[i]); |
189 if (length != this.length) { | 189 if (length != this.length) { |
190 throw new ConcurrentModificationError(this); | 190 throw new ConcurrentModificationError(this); |
191 } | 191 } |
192 } | 192 } |
193 return value; | 193 return value; |
194 } | 194 } |
195 | 195 |
196 fold(var initialValue, combine(var previousValue, E element)) { | 196 /*=T*/ fold/*<T>*/(var/*=T*/ initialValue, /*=T*/combine(var/*=T*/ previousVal
ue, E element)) { |
197 var value = initialValue; | 197 var value = initialValue; |
198 int length = this.length; | 198 int length = this.length; |
199 for (int i = 0; i < length; i++) { | 199 for (int i = 0; i < length; i++) { |
200 value = combine(value, this[i]); | 200 value = combine(value, this[i]); |
201 if (length != this.length) { | 201 if (length != this.length) { |
202 throw new ConcurrentModificationError(this); | 202 throw new ConcurrentModificationError(this); |
203 } | 203 } |
204 } | 204 } |
205 return value; | 205 return value; |
206 } | 206 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 for (E element in iterable) { | 491 for (E element in iterable) { |
492 this[index++] = element; | 492 this[index++] = element; |
493 } | 493 } |
494 } | 494 } |
495 } | 495 } |
496 | 496 |
497 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 497 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
498 | 498 |
499 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 499 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
500 } | 500 } |
OLD | NEW |