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

Side by Side Diff: runtime/lib/array.dart

Issue 11727007: Add min and max to Iterable and Stream. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Address review comments. Fix T->E in Iterable. 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 | runtime/lib/byte_array.dart » ('j') | sdk/lib/async/stream.dart » ('J')
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 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
7 class _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 8
9 factory _ObjectArray(int length) native "ObjectArray_allocate"; 9 factory _ObjectArray(int length) native "ObjectArray_allocate";
10 10
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (length > 0) return this[length - 1]; 185 if (length > 0) return this[length - 1];
186 throw new StateError("No elements"); 186 throw new StateError("No elements");
187 } 187 }
188 188
189 E get single { 189 E get single {
190 if (length == 1) return this[0]; 190 if (length == 1) return this[0];
191 if (length == 0) throw new StateError("No elements"); 191 if (length == 0) throw new StateError("No elements");
192 throw new StateError("More than one element"); 192 throw new StateError("More than one element");
193 } 193 }
194 194
195 E min([int compare(E a, E b)]) => Collections.min(this, compare);
196
197 E max([int compare(E a, E b)]) => Collections.max(this, compare);
198
195 List<E> toList() { 199 List<E> toList() {
196 return new List<E>.from(this); 200 return new List<E>.from(this);
197 } 201 }
198 202
199 Set<E> toSet() { 203 Set<E> toSet() {
200 return new Set<E>.from(this); 204 return new Set<E>.from(this);
201 } 205 }
202 } 206 }
203 207
204 208
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 431 }
428 _position = _length; 432 _position = _length;
429 _current = null; 433 _current = null;
430 return false; 434 return false;
431 } 435 }
432 436
433 E get current { 437 E get current {
434 return _current; 438 return _current;
435 } 439 }
436 } 440 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/byte_array.dart » ('j') | sdk/lib/async/stream.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698