| 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The [Iterable] interface allows to get an [Iterator] out of an | 8 * The [Iterable] interface allows to get an [Iterator] out of an |
| 9 * [Iterable] object. | 9 * [Iterable] object. |
| 10 * | 10 * |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 * This method returns a view of the mapped elements. As long as the | 45 * This method returns a view of the mapped elements. As long as the |
| 46 * returned [Iterable] is not iterated over, the supplied function [f] will | 46 * returned [Iterable] is not iterated over, the supplied function [f] will |
| 47 * not be invoked. The transformed elements will not be cached. Iterating | 47 * not be invoked. The transformed elements will not be cached. Iterating |
| 48 * multiple times over the the returned [Iterable] will invoke the supplied | 48 * multiple times over the the returned [Iterable] will invoke the supplied |
| 49 * function [f] multiple times on the same element. | 49 * function [f] multiple times on the same element. |
| 50 */ | 50 */ |
| 51 Iterable map(f(E element)); | 51 Iterable map(f(E element)); |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Returns a lazy [Iterable] with all elements that satisfy the | 54 * Returns a lazy [Iterable] with all elements that satisfy the |
| 55 * predicate [f]. | 55 * predicate [test]. |
| 56 * | 56 * |
| 57 * This method returns a view of the mapped elements. As long as the | 57 * This method returns a view of the mapped elements. As long as the |
| 58 * returned [Iterable] is not iterated over, the supplied function [f] will | 58 * returned [Iterable] is not iterated over, the supplied function [test] will |
| 59 * not be invoked. Iterating will not cache results, and thus iterating | 59 * not be invoked. Iterating will not cache results, and thus iterating |
| 60 * multiple times over the the returned [Iterable] will invoke the supplied | 60 * multiple times over the the returned [Iterable] will invoke the supplied |
| 61 * function [f] multiple times on the same element. | 61 * function [test] multiple times on the same element. |
| 62 */ | 62 */ |
| 63 Iterable<E> where(bool f(E element)); | 63 Iterable<E> where(bool test(E element)); |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Expand each element of this [Iterable] into zero or more elements. | 66 * Expand each element of this [Iterable] into zero or more elements. |
| 67 * | 67 * |
| 68 * The resulting Iterable will run through the elements returned | 68 * The resulting Iterable will run through the elements returned |
| 69 * by [f] for each element of this, in order. | 69 * by [f] for each element of this, in order. |
| 70 * | 70 * |
| 71 * The returned [Iterable] is lazy, and will call [f] for each element | 71 * The returned [Iterable] is lazy, and will call [f] for each element |
| 72 * of this every time it's iterated. | 72 * of this every time it's iterated. |
| 73 */ | 73 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 * Example of calculating the sum of an iterable: | 105 * Example of calculating the sum of an iterable: |
| 106 * | 106 * |
| 107 * iterable.fold(0, (prev, element) => prev + element); | 107 * iterable.fold(0, (prev, element) => prev + element); |
| 108 * | 108 * |
| 109 */ | 109 */ |
| 110 dynamic fold(var initialValue, | 110 dynamic fold(var initialValue, |
| 111 dynamic combine(var previousValue, E element)); | 111 dynamic combine(var previousValue, E element)); |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * Returns true if every elements of this collection satisify the | 114 * Returns true if every elements of this collection satisify the |
| 115 * predicate [f]. Returns `false` otherwise. | 115 * predicate [test]. Returns `false` otherwise. |
| 116 */ | 116 */ |
| 117 bool every(bool f(E element)); | 117 bool every(bool test(E element)); |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * Converts each element to a [String] and concatenates the strings. | 120 * Converts each element to a [String] and concatenates the strings. |
| 121 * | 121 * |
| 122 * Converts each element to a [String] by calling [Object.toString] on it. | 122 * Converts each element to a [String] by calling [Object.toString] on it. |
| 123 * Then concatenates the strings, optionally separated by the [separator] | 123 * Then concatenates the strings, optionally separated by the [separator] |
| 124 * string. | 124 * string. |
| 125 */ | 125 */ |
| 126 String join([String separator = ""]) { | 126 String join([String separator = ""]) { |
| 127 StringBuffer buffer = new StringBuffer(); | 127 StringBuffer buffer = new StringBuffer(); |
| 128 buffer.writeAll(this, separator); | 128 buffer.writeAll(this, separator); |
| 129 return buffer.toString(); | 129 return buffer.toString(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * Returns true if one element of this collection satisfies the | 133 * Returns true if one element of this collection satisfies the |
| 134 * predicate [f]. Returns false otherwise. | 134 * predicate [test]. Returns false otherwise. |
| 135 */ | 135 */ |
| 136 bool any(bool f(E element)); | 136 bool any(bool test(E element)); |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * Creates a [List] containing the elements of this [Iterable]. | 139 * Creates a [List] containing the elements of this [Iterable]. |
| 140 * | 140 * |
| 141 * The elements will be in iteration order. The list is fixed-length | 141 * The elements will be in iteration order. The list is fixed-length |
| 142 * if [growable] is false. | 142 * if [growable] is false. |
| 143 */ | 143 */ |
| 144 List<E> toList({ bool growable: true }); | 144 List<E> toList({ bool growable: true }); |
| 145 | 145 |
| 146 /** | 146 /** |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 E get last; | 219 E get last; |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * Returns the single element in `this`. | 222 * Returns the single element in `this`. |
| 223 * | 223 * |
| 224 * If `this` is empty or has more than one element throws a [StateError]. | 224 * If `this` is empty or has more than one element throws a [StateError]. |
| 225 */ | 225 */ |
| 226 E get single; | 226 E get single; |
| 227 | 227 |
| 228 /** | 228 /** |
| 229 * Returns the first element that satisfies the given predicate [f]. | 229 * Returns the first element that satisfies the given predicate [test]. |
| 230 * | 230 * |
| 231 * If none matches, the result of invoking the [orElse] function is | 231 * If none matches, the result of invoking the [orElse] function is |
| 232 * returned. By default, when [orElse] is `null`, a [StateError] is | 232 * returned. By default, when [orElse] is `null`, a [StateError] is |
| 233 * thrown. | 233 * thrown. |
| 234 */ | 234 */ |
| 235 E firstWhere(bool test(E value), { E orElse() }); | 235 E firstWhere(bool test(E element), { E orElse() }); |
| 236 | 236 |
| 237 /** | 237 /** |
| 238 * Returns the last element that satisfies the given predicate [f]. | 238 * Returns the last element that satisfies the given predicate [test]. |
| 239 * | 239 * |
| 240 * If none matches, the result of invoking the [orElse] function is | 240 * If none matches, the result of invoking the [orElse] function is |
| 241 * returned. By default, when [orElse] is `null`, a [StateError] is | 241 * returned. By default, when [orElse] is `null`, a [StateError] is |
| 242 * thrown. | 242 * thrown. |
| 243 */ | 243 */ |
| 244 E lastWhere(bool test(E value), {E orElse()}); | 244 E lastWhere(bool test(E element), {E orElse()}); |
| 245 | 245 |
| 246 /** | 246 /** |
| 247 * Returns the single element that satisfies [f]. If no or more than one | 247 * Returns the single element that satisfies [test]. If no or more than one |
| 248 * element match then a [StateError] is thrown. | 248 * element match then a [StateError] is thrown. |
| 249 */ | 249 */ |
| 250 E singleWhere(bool test(E value)); | 250 E singleWhere(bool test(E element)); |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * Returns the [index]th element. | 253 * Returns the [index]th element. |
| 254 * | 254 * |
| 255 * If `this` has fewer than [index] elements throws a [RangeError]. | 255 * If `this` has fewer than [index] elements throws a [RangeError]. |
| 256 * | 256 * |
| 257 * Note: if `this` does not have a deterministic iteration order then the | 257 * Note: if `this` does not have a deterministic iteration order then the |
| 258 * function may simply return any element without any iteration if there are | 258 * function may simply return any element without any iteration if there are |
| 259 * at least [index] elements in `this`. | 259 * at least [index] elements in `this`. |
| 260 */ | 260 */ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 */ | 298 */ |
| 299 abstract class BidirectionalIterator<E> implements Iterator<E> { | 299 abstract class BidirectionalIterator<E> implements Iterator<E> { |
| 300 /** | 300 /** |
| 301 * Move back to the previous element. | 301 * Move back to the previous element. |
| 302 * | 302 * |
| 303 * Returns true and updates [current] if successful. Returns false | 303 * Returns true and updates [current] if successful. Returns false |
| 304 * and sets [current] to null if there is no previous element. | 304 * and sets [current] to null if there is no previous element. |
| 305 */ | 305 */ |
| 306 bool movePrevious(); | 306 bool movePrevious(); |
| 307 } | 307 } |
| OLD | NEW |