Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: corelib/src/implementation/queue.dart

Issue 10854118: Add reduce to Queue. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/collection_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 6 /**
7 * An entry in a doubly linked list. It contains a pointer to the next 7 * An entry in a doubly linked list. It contains a pointer to the next
8 * entry, the previous entry, and the boxed element. 8 * entry, the previous entry, and the boxed element.
9 */ 9 */
10 class DoubleLinkedQueueEntry<E> { 10 class DoubleLinkedQueueEntry<E> {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 Queue other = new Queue(); 209 Queue other = new Queue();
210 DoubleLinkedQueueEntry<E> entry = _sentinel._next; 210 DoubleLinkedQueueEntry<E> entry = _sentinel._next;
211 while (entry !== _sentinel) { 211 while (entry !== _sentinel) {
212 DoubleLinkedQueueEntry<E> nextEntry = entry._next; 212 DoubleLinkedQueueEntry<E> nextEntry = entry._next;
213 other.addLast(f(entry._element)); 213 other.addLast(f(entry._element));
214 entry = nextEntry; 214 entry = nextEntry;
215 } 215 }
216 return other; 216 return other;
217 } 217 }
218 218
219 Dynamic reduce(Dynamic initialValue,
220 Dynamic combine(Dynamic previousValue, E element)) {
221 return Collections.reduce(this, initialValue, combine);
222 }
219 223
220 Queue<E> filter(bool f(E element)) { 224 Queue<E> filter(bool f(E element)) {
221 Queue<E> other = new Queue<E>(); 225 Queue<E> other = new Queue<E>();
222 DoubleLinkedQueueEntry<E> entry = _sentinel._next; 226 DoubleLinkedQueueEntry<E> entry = _sentinel._next;
223 while (entry !== _sentinel) { 227 while (entry !== _sentinel) {
224 DoubleLinkedQueueEntry<E> nextEntry = entry._next; 228 DoubleLinkedQueueEntry<E> nextEntry = entry._next;
225 if (f(entry._element)) other.addLast(entry._element); 229 if (f(entry._element)) other.addLast(entry._element);
226 entry = nextEntry; 230 entry = nextEntry;
227 } 231 }
228 return other; 232 return other;
(...skipping 21 matching lines...) Expand all
250 } 254 }
251 255
252 E next() { 256 E next() {
253 if (!hasNext()) { 257 if (!hasNext()) {
254 throw const NoMoreElementsException(); 258 throw const NoMoreElementsException();
255 } 259 }
256 _currentEntry = _currentEntry._next; 260 _currentEntry = _currentEntry._next;
257 return _currentEntry.element; 261 return _currentEntry.element;
258 } 262 }
259 } 263 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/collection_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698