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

Side by Side Diff: sdk/lib/core/set.dart

Issue 11377102: Remove named function literals from library and tests (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « sdk/lib/core/queue.dart ('k') | sdk/lib/io/http_impl.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) 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 /** 5 /**
6 * This class is the public interface of a set. A set is a collection 6 * This class is the public interface of a set. A set is a collection
7 * without duplicates. 7 * without duplicates.
8 */ 8 */
9 abstract class Set<E> extends Collection<E> { 9 abstract class Set<E> extends Collection<E> {
10 factory Set() => new _HashSetImpl<E>(); 10 factory Set() => new _HashSetImpl<E>();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return _backingMap.containsKey(value); 103 return _backingMap.containsKey(value);
104 } 104 }
105 105
106 bool remove(E value) { 106 bool remove(E value) {
107 if (!_backingMap.containsKey(value)) return false; 107 if (!_backingMap.containsKey(value)) return false;
108 _backingMap.remove(value); 108 _backingMap.remove(value);
109 return true; 109 return true;
110 } 110 }
111 111
112 void addAll(Collection<E> collection) { 112 void addAll(Collection<E> collection) {
113 collection.forEach(void _(E value) { 113 collection.forEach((E value) {
114 add(value); 114 add(value);
115 }); 115 });
116 } 116 }
117 117
118 Set<E> intersection(Collection<E> collection) { 118 Set<E> intersection(Collection<E> collection) {
119 Set<E> result = new Set<E>(); 119 Set<E> result = new Set<E>();
120 collection.forEach(void _(E value) { 120 collection.forEach((E value) {
121 if (contains(value)) result.add(value); 121 if (contains(value)) result.add(value);
122 }); 122 });
123 return result; 123 return result;
124 } 124 }
125 125
126 bool isSubsetOf(Collection<E> other) { 126 bool isSubsetOf(Collection<E> other) {
127 return new Set<E>.from(other).containsAll(this); 127 return new Set<E>.from(other).containsAll(this);
128 } 128 }
129 129
130 void removeAll(Collection<E> collection) { 130 void removeAll(Collection<E> collection) {
131 collection.forEach(void _(E value) { 131 collection.forEach((E value) {
132 remove(value); 132 remove(value);
133 }); 133 });
134 } 134 }
135 135
136 bool containsAll(Collection<E> collection) { 136 bool containsAll(Collection<E> collection) {
137 return collection.every(bool _(E value) { 137 return collection.every((E value) {
138 return contains(value); 138 return contains(value);
139 }); 139 });
140 } 140 }
141 141
142 void forEach(void f(E element)) { 142 void forEach(void f(E element)) {
143 _backingMap.forEach(void _(E key, E value) { 143 _backingMap.forEach((E key, E value) {
144 f(key); 144 f(key);
145 }); 145 });
146 } 146 }
147 147
148 Set map(f(E element)) { 148 Set map(f(E element)) {
149 Set result = new Set(); 149 Set result = new Set();
150 _backingMap.forEach(void _(E key, E value) { 150 _backingMap.forEach((E key, E value) {
151 result.add(f(key)); 151 result.add(f(key));
152 }); 152 });
153 return result; 153 return result;
154 } 154 }
155 155
156 Dynamic reduce(Dynamic initialValue, 156 Dynamic reduce(Dynamic initialValue,
157 Dynamic combine(Dynamic previousValue, E element)) { 157 Dynamic combine(Dynamic previousValue, E element)) {
158 return Collections.reduce(this, initialValue, combine); 158 return Collections.reduce(this, initialValue, combine);
159 } 159 }
160 160
161 Set<E> filter(bool f(E element)) { 161 Set<E> filter(bool f(E element)) {
162 Set<E> result = new Set<E>(); 162 Set<E> result = new Set<E>();
163 _backingMap.forEach(void _(E key, E value) { 163 _backingMap.forEach((E key, E value) {
164 if (f(key)) result.add(key); 164 if (f(key)) result.add(key);
165 }); 165 });
166 return result; 166 return result;
167 } 167 }
168 168
169 bool every(bool f(E element)) { 169 bool every(bool f(E element)) {
170 Collection<E> keys = _backingMap.keys; 170 Collection<E> keys = _backingMap.keys;
171 return keys.every(f); 171 return keys.every(f);
172 } 172 }
173 173
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 238 }
239 239
240 // The entries in the set. May contain null or the sentinel value. 240 // The entries in the set. May contain null or the sentinel value.
241 List<E> _entries; 241 List<E> _entries;
242 242
243 // The next valid index in [_entries] or the length of [entries_]. 243 // The next valid index in [_entries] or the length of [entries_].
244 // If it is the length of [_entries], calling [hasNext] on the 244 // If it is the length of [_entries], calling [hasNext] on the
245 // iterator will return false. 245 // iterator will return false.
246 int _nextValidIndex; 246 int _nextValidIndex;
247 } 247 }
OLDNEW
« no previous file with comments | « sdk/lib/core/queue.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698