make (range) return an Iterable & Iterator
This commit is contained in:
@@ -239,11 +239,11 @@ class Prelude {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ranges with a min, exclusive max, and step size, just like Python.
|
// Ranges with a min, exclusive max, and step size, just like Python.
|
||||||
public static function range(min, max, step):Iterator<Int> {
|
public static function range(min, max, step):Iterator<Int> & Iterable<Int> {
|
||||||
if (step <= 0 || max < min)
|
if (step <= 0 || max < min)
|
||||||
throw "(range...) can only count up";
|
throw "(range...) can only count up";
|
||||||
var count = min;
|
var count = min;
|
||||||
return {
|
var iterator = {
|
||||||
next: () -> {
|
next: () -> {
|
||||||
var oldCount = count;
|
var oldCount = count;
|
||||||
count += step;
|
count += step;
|
||||||
@@ -253,6 +253,11 @@ class Prelude {
|
|||||||
count < max;
|
count < max;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return {
|
||||||
|
iterator: () -> iterator,
|
||||||
|
next: () -> iterator.next(),
|
||||||
|
hasNext: () -> iterator.hasNext()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _joinPath(parts:Array<Dynamic>) {
|
static function _joinPath(parts:Array<Dynamic>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user