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

Side by Side Diff: sdk/lib/collection/collections.dart

Issue 12262037: Make List.skip, List.take and List.reversed return Iterables, not Lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, small fixes. 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
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/js_array.dart ('k') | 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) 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 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * This class provides default implementations for Iterables (including Lists). 8 * This class provides default implementations for Iterables (including Lists).
9 * 9 *
10 * Once Dart receives Mixins it will be replaced with mixin classes. 10 * Once Dart receives Mixins it will be replaced with mixin classes.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 311
312 static Iterable where(Iterable iterable, bool f(var element)) { 312 static Iterable where(Iterable iterable, bool f(var element)) {
313 return new WhereIterable(iterable, f); 313 return new WhereIterable(iterable, f);
314 } 314 }
315 315
316 static Iterable map(Iterable iterable, f(var element)) { 316 static Iterable map(Iterable iterable, f(var element)) {
317 return new MappedIterable(iterable, f); 317 return new MappedIterable(iterable, f);
318 } 318 }
319 319
320 static Iterable mapList(List list, f(var element)) { 320 static Iterable mapList(List list, f(var element)) {
321 return new MappedListIterable(list, f, 0, null); 321 return new MappedListIterable(list, f);
322 } 322 }
323 323
324 static List mappedByList(List list, f(var element)) { 324 static List mappedByList(List list, f(var element)) {
325 // This is currently a List as well as an Iterable. 325 // This is currently a List as well as an Iterable.
326 return new MappedList(list, f); 326 return new MappedList(list, f);
327 } 327 }
328 328
329 static Iterable expand(Iterable iterable, Iterable f(var element)) { 329 static Iterable expand(Iterable iterable, Iterable f(var element)) {
330 return new ExpandIterable(iterable, f); 330 return new ExpandIterable(iterable, f);
331 } 331 }
332 332
333 static Iterable takeList(List list, int n) { 333 static Iterable takeList(List list, int n) {
334 // The generic type is currently lost. It will be fixed with mixins. 334 // The generic type is currently lost. It will be fixed with mixins.
335 // This is currently a List as well as an Iterable. 335 // This is currently a List as well as an Iterable.
336 return new ListView(list, 0, n); 336 return new SubListIterable(list, 0, n);
337 } 337 }
338 338
339 static Iterable takeWhile(Iterable iterable, bool test(var value)) { 339 static Iterable takeWhile(Iterable iterable, bool test(var value)) {
340 // The generic type is currently lost. It will be fixed with mixins. 340 // The generic type is currently lost. It will be fixed with mixins.
341 return new TakeWhileIterable(iterable, test); 341 return new TakeWhileIterable(iterable, test);
342 } 342 }
343 343
344 static Iterable skipList(List list, int n) { 344 static Iterable skipList(List list, int n) {
345 // The generic type is currently lost. It will be fixed with mixins. 345 // The generic type is currently lost. It will be fixed with mixins.
346 // This is currently a List as well as an Iterable. 346 // This is currently a List as well as an Iterable.
347 return new ListView(list, n, null); 347 return new SubListIterable(list, n, null);
348 } 348 }
349 349
350 static Iterable skipWhile(Iterable iterable, bool test(var value)) { 350 static Iterable skipWhile(Iterable iterable, bool test(var value)) {
351 // The generic type is currently lost. It will be fixed with mixins. 351 // The generic type is currently lost. It will be fixed with mixins.
352 return new SkipWhileIterable(iterable, test); 352 return new SkipWhileIterable(iterable, test);
353 } 353 }
354 354
355 static List reversedList(List l) { 355 static Iterable reversedList(List l) {
356 return new ReversedListView(l, 0, null); 356 return new ReversedListIterable(l);
357 } 357 }
358 358
359 static void sortList(List l, int compare(a, b)) { 359 static void sortList(List l, int compare(a, b)) {
360 if (compare == null) compare = Comparable.compare; 360 if (compare == null) compare = Comparable.compare;
361 Sort.sort(l, compare); 361 Sort.sort(l, compare);
362 } 362 }
363 } 363 }
364 364
365 /** 365 /**
366 * The [Collections] class implements static methods useful when 366 * The [Collections] class implements static methods useful when
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 => IterableMixinWorkaround.skipList(list, n); 493 => IterableMixinWorkaround.skipList(list, n);
494 494
495 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ 495 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/
496 @deprecated 496 @deprecated
497 static Iterable skipWhile(Iterable iterable, bool test(var value)) 497 static Iterable skipWhile(Iterable iterable, bool test(var value))
498 => IterableMixinWorkaround.skipWhile(iterable, test); 498 => IterableMixinWorkaround.skipWhile(iterable, test);
499 499
500 static String collectionToString(Collection c) 500 static String collectionToString(Collection c)
501 => ToString.collectionToString(c); 501 => ToString.collectionToString(c);
502 } 502 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/js_array.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698