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

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

Issue 12041045: List.mappedBy/skip/take returns a List. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 11 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 | sdk/lib/core/list.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) 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 * Class implementing the read-operations on [List]. 8 * Class implementing the read-operations on [List].
9 * 9 *
10 * Implements all read-only operations, except [:operator[]:] and [:length:], 10 * Implements all read-only operations, except [:operator[]:] and [:length:],
11 * in terms of those two operations. 11 * in terms of those two operations.
12 */ 12 */
13 abstract class ListBase<E> extends Iterable<E> implements List<E> { 13 abstract class ListBase<E> extends Collection<E> implements List<E> {
14 Iterator<E> get iterator => new ListIterator(this); 14 Iterator<E> get iterator => new ListIterator(this);
15 15
16 void forEach(f(E element)) { 16 void forEach(f(E element)) {
17 for (int i = 0; i < this.length; i++) f(this[i]); 17 for (int i = 0; i < this.length; i++) f(this[i]);
18 } 18 }
19 19
20 bool contains(E value) { 20 bool contains(E value) {
21 for (int i = 0; i < length; i++) { 21 for (int i = 0; i < length; i++) {
22 if (this[i] == value) return true; 22 if (this[i] == value) return true;
23 } 23 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 List<E> getRange(int start, int length) { 88 List<E> getRange(int start, int length) {
89 List<E> result = <E>[]; 89 List<E> result = <E>[];
90 for (int i = 0; i < length; i++) { 90 for (int i = 0; i < length; i++) {
91 result.add(this[start + i]); 91 result.add(this[start + i]);
92 } 92 }
93 return result; 93 return result;
94 } 94 }
95 95
96 List mappedBy(f(E element)) {
97 return new MappedList(this, f);
98 }
99
100 List<E> take(int n) {
101 return new ListView(this, 0, n);
102 }
103
104 List<E> skip(int n) {
105 return new ListView(this, n, null);
106 }
107
96 String toString() => Collections.collectionToString(this); 108 String toString() => Collections.collectionToString(this);
97 } 109 }
98 110
99 /** 111 /**
100 * Abstract class implementing the non-length changing operations of [List]. 112 * Abstract class implementing the non-length changing operations of [List].
101 */ 113 */
102 abstract class FixedLengthListBase<E> extends ListBase<E> { 114 abstract class FixedLengthListBase<E> extends ListBase<E> {
103 void operator[]=(int index, E value); 115 void operator[]=(int index, E value);
104 116
105 List<E> get reversed => new ReversedListView<E>(this, 0, null); 117 List<E> get reversed => new ReversedListView<E>(this, 0, null);
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 throw new ConcurrentModificationError(list); 534 throw new ConcurrentModificationError(list);
523 } 535 }
524 if (_index <= _start) return false; 536 if (_index <= _start) return false;
525 _index -= 1; 537 _index -= 1;
526 _current = _list[_index]; 538 _current = _list[_index];
527 return true; 539 return true;
528 } 540 }
529 541
530 E get current => _current; 542 E get current => _current;
531 } 543 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698