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

Side by Side Diff: sdk/lib/collection_dev/list.dart

Issue 12094103: Added MappedListIterable/Iterator to implement map() on Lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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.collection.dev; 5 part of dart.collection.dev;
6 6
7 /** 7 /**
8 * A wrapper for any [Iterable] that only exposes the [Iterable] interface.
9 */
10 class IterableView<E> extends Iterable<E> {
floitsch 2013/02/01 15:00:36 Is this class used?
Lasse Reichstein Nielsen 2013/02/01 15:13:57 Whoops, no. Didn't need it anyway, and forgot to r
11 final Iterable<E> _source;
12
13 IterableView(this._source);
14
15 Iterator<E> get iterator => _source.iterator;
16
17 void forEach(void action(E element)) {
18 _source.forEach(action);
19 }
20
21 bool get isEmpty => _source.isEmpty;
22
23 int get length => _source.length;
24
25 E get first => _source.first;
26
27 E get last => _source.last;
28
29 E get single => _source.single;
30
31 E elementAt(int index) => _source.elementAt(index);
32
33 bool contains(E element) => _source.contains(element);
34
35 bool every(bool test(E element)) => _source.every(test);
36
37 bool any(bool test(E element)) => _source.any(test);
38
39 E firstMatching(bool test(E element), { E orElse() }) {
40 return _source.firstMatching(test, orElse: orElse);
41 }
42
43 E lastMatching(bool test(E element), { E orElse() }) {
44 return _source.lastMatching(test, orElse: orElse);
45 }
46
47 E singleMatching(bool test(E element), { E orElse() }) {
48 return _source.singleMatching(test, orElse: orElse);
49 }
50
51 int min([int compare(E a, E b)]) => _source.min(compare);
52
53 int max([int compare(E a, E b)]) => _source.max(compare);
54
55 String join([String separator]) => _source.join(separator);
56
57 Iterable<E> where(bool test(E element)) => _source.where(test);
58
59 Iterable map(f(E element)) => _source.map(f);
60
61 Iterable mappedBy(f(E element)) => _source.mappedBy(f);
62
63 reduce(var initialValue, combine(var previousValue, E element)) {
64 return _source.reduce(initialValue, combine);
65 }
66
67 Iterable<E> skip(int count) => _source.skip(count);
68
69 Iterable<E> skipWhile(bool test(E element)) => _source.skipWhile(test);
70
71 Iterable<E> take(int count) => _source.take(count);
72
73 Iterable<E> takeWhile(bool test(E element)) => _source.takeWhile(test);
74
75 List toList() => _source.toList();
76
77 Set toSet() => _source.toSet();
78 }
79
80 /**
8 * Class implementing the read-operations on [List]. 81 * Class implementing the read-operations on [List].
9 * 82 *
10 * Implements all read-only operations, except [:operator[]:] and [:length:], 83 * Implements all read-only operations, except [:operator[]:] and [:length:],
11 * in terms of those two operations. 84 * in terms of those two operations.
12 */ 85 */
13 abstract class ListBase<E> extends Collection<E> implements List<E> { 86 abstract class ListBase<E> extends Collection<E> implements List<E> {
14 Iterator<E> get iterator => new ListIterator(this); 87 Iterator<E> get iterator => new ListIterator(this);
15 88
16 void forEach(f(E element)) { 89 void forEach(f(E element)) {
17 for (int i = 0; i < this.length; i++) f(this[i]); 90 for (int i = 0; i < this.length; i++) f(this[i]);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 throw new ConcurrentModificationError(_list); 613 throw new ConcurrentModificationError(_list);
541 } 614 }
542 if (_index <= _start) return false; 615 if (_index <= _start) return false;
543 _index -= 1; 616 _index -= 1;
544 _current = _list[_index]; 617 _current = _list[_index];
545 return true; 618 return true;
546 } 619 }
547 620
548 E get current => _current; 621 E get current => _current;
549 } 622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698