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

Side by Side Diff: tools/dom/src/WrappedList.dart

Issue 14071002: Added new version of reduce. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed more uses of max, and a few bugs. Created 7 years, 8 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
OLDNEW
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.dom.html; 5 part of dart.dom.html;
6 6
7 /** 7 /**
8 * A list which just wraps another list, for either intercepting list calls or 8 * A list which just wraps another list, for either intercepting list calls or
9 * retyping the list (for example, from List<A> to List<B> where B extends A). 9 * retyping the list (for example, from List<A> to List<B> where B extends A).
10 */ 10 */
11 class _WrappedList<E> implements List<E> { 11 class _WrappedList<E> implements List<E> {
12 final List _list; 12 final List _list;
13 13
14 _WrappedList(this._list); 14 _WrappedList(this._list);
15 15
16 // Iterable APIs 16 // Iterable APIs
17 17
18 Iterator<E> get iterator => new _WrappedIterator(_list.iterator); 18 Iterator<E> get iterator => new _WrappedIterator(_list.iterator);
19 19
20 Iterable map(f(E element)) => _list.map(f); 20 Iterable map(f(E element)) => _list.map(f);
21 21
22 Iterable<E> where(bool f(E element)) => _list.where(f); 22 Iterable<E> where(bool f(E element)) => _list.where(f);
23 23
24 Iterable expand(Iterable f(E element)) => _list.expand(f); 24 Iterable expand(Iterable f(E element)) => _list.expand(f);
25 25
26 bool contains(E element) => _list.contains(element); 26 bool contains(E element) => _list.contains(element);
27 27
28 void forEach(void f(E element)) { _list.forEach(f); } 28 void forEach(void f(E element)) { _list.forEach(f); }
29 29
30 dynamic reduce(initialValue, combine(previousValue, E element)) => 30 E reduce(E combine(E value, E element)) =>
31 _list.reduce(initialValue, combine); 31 _list.reduce(combine);
32 32
33 dynamic fold(initialValue, combine(previousValue, E element)) => 33 dynamic fold(initialValue, combine(previousValue, E element)) =>
34 _list.fold(initialValue, combine); 34 _list.fold(initialValue, combine);
35 35
36 bool every(bool f(E element)) => _list.every(f); 36 bool every(bool f(E element)) => _list.every(f);
37 37
38 String join([String separator = ""]) => _list.join(separator); 38 String join([String separator = ""]) => _list.join(separator);
39 39
40 bool any(bool f(E element)) => _list.any(f); 40 bool any(bool f(E element)) => _list.any(f);
41 41
42 List<E> toList({ bool growable: true }) => 42 List<E> toList({ bool growable: true }) =>
43 new List.from(_list, growable: growable); 43 new List.from(_list, growable: growable);
44 44
45 Set<E> toSet() => _list.toSet(); 45 Set<E> toSet() => _list.toSet();
46 46
47 int get length => _list.length; 47 int get length => _list.length;
48 48
49 E min([int compare(E a, E b)]) => _list.min(compare);
50
51 E max([int compare(E a, E b)]) => _list.max(compare);
52
53 bool get isEmpty => _list.isEmpty; 49 bool get isEmpty => _list.isEmpty;
54 50
55 Iterable<E> take(int n) => _list.take(n); 51 Iterable<E> take(int n) => _list.take(n);
56 52
57 Iterable<E> takeWhile(bool test(E value)) => _list.takeWhile(test); 53 Iterable<E> takeWhile(bool test(E value)) => _list.takeWhile(test);
58 54
59 Iterable<E> skip(int n) => _list.skip(n); 55 Iterable<E> skip(int n) => _list.skip(n);
60 56
61 Iterable<E> skipWhile(bool test(E value)) => _list.skipWhile(test); 57 Iterable<E> skipWhile(bool test(E value)) => _list.skipWhile(test);
62 58
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 Iterator _iterator; 143 Iterator _iterator;
148 144
149 _WrappedIterator(this._iterator); 145 _WrappedIterator(this._iterator);
150 146
151 bool moveNext() { 147 bool moveNext() {
152 return _iterator.moveNext(); 148 return _iterator.moveNext();
153 } 149 }
154 150
155 E get current => _iterator.current; 151 E get current => _iterator.current;
156 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698