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

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

Issue 551063003: Add Iterable.range, List.range and int.to. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/core/int.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) 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 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * An object that uses an [Iterator] to serve objects one at a time. 8 * An object that uses an [Iterator] to serve objects one at a time.
9 * 9 *
10 * You can iterate over all objects served by an Iterable object 10 * You can iterate over all objects served by an Iterable object
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 * 47 *
48 * As an Iterable, [:new Iterable.generate(n, generator)):] is equivalent to 48 * As an Iterable, [:new Iterable.generate(n, generator)):] is equivalent to
49 * [:const [0, ..., n - 1].map(generator):] 49 * [:const [0, ..., n - 1].map(generator):]
50 */ 50 */
51 factory Iterable.generate(int count, [E generator(int index)]) { 51 factory Iterable.generate(int count, [E generator(int index)]) {
52 if (count <= 0) return new EmptyIterable<E>(); 52 if (count <= 0) return new EmptyIterable<E>();
53 return new _GeneratorIterable<E>(count, generator); 53 return new _GeneratorIterable<E>(count, generator);
54 } 54 }
55 55
56 /** 56 /**
57 * Create an `Iterable<int>` iterating from `from` to `to`, inclusive.
58 *
59 * The iteration starts with `from` as the first value, and then
60 * progresses towards `to` in increments of `step`, and stops when reaching
61 * or overshooting `to`. If it hits `to` the `to` value is included,
floitsch 2014/09/09 09:37:14 Strongly oppose. We have a getRange in this class
62 * otherwise it isn't.
63 *
64 * If `to` is less than `from`, the values are in decreasing order.
65 *
66 * The [step] value must always be positive. It defaults to `1`.
67 */
68 static Iterable<int> range(int from, int to, {int step: 1}) {
69 if (step <= 0) {
70 throw new RangeError.value("Step must be positive, was $step");
71 }
72 final int delta = to - from;
73 if (delta < 0) {
74 step = -step;
75 }
76 final int steps = delta ~/ step + 1;
77 return new Iterable<int>.generate(steps, (n) => from + n * step);
78 }
79
80 /**
57 * Returns a new `Iterator` that allows iterating the elements of this 81 * Returns a new `Iterator` that allows iterating the elements of this
58 * `Iterable`. 82 * `Iterable`.
59 */ 83 */
60 Iterator<E> get iterator; 84 Iterator<E> get iterator;
61 85
62 /** 86 /**
63 * Returns a new lazy [Iterable] with elements that are created by 87 * Returns a new lazy [Iterable] with elements that are created by
64 * calling `f` on the elements of this `Iterable`. 88 * calling `f` on the elements of this `Iterable`.
65 * 89 *
66 * This method returns a view of the mapped elements. As long as the 90 * This method returns a view of the mapped elements. As long as the
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 */ 391 */
368 abstract class BidirectionalIterator<E> implements Iterator<E> { 392 abstract class BidirectionalIterator<E> implements Iterator<E> {
369 /** 393 /**
370 * Move back to the previous element. 394 * Move back to the previous element.
371 * 395 *
372 * Returns true and updates [current] if successful. Returns false 396 * Returns true and updates [current] if successful. Returns false
373 * and sets [current] to null if there is no previous element. 397 * and sets [current] to null if there is no previous element.
374 */ 398 */
375 bool movePrevious(); 399 bool movePrevious();
376 } 400 }
OLDNEW
« no previous file with comments | « sdk/lib/core/int.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698