(range...)

This commit is contained in:
2020-12-07 19:12:22 -07:00
parent 6866c7133d
commit 74d070d7b3
4 changed files with 45 additions and 2 deletions

View File

@@ -186,6 +186,23 @@ class Prelude {
];
}
// Ranges with a min, exclusive max, and step size, just like Python.
public static function range(min, max, step):Iterator<Int> {
if (step <= 0)
throw "(range...) can only count up";
var count = min;
return {
next: () -> {
var oldCount = count;
count += step;
oldCount;
},
hasNext: () -> {
count < max;
}
};
}
public static dynamic function truthy(v:Any) {
return switch (Type.typeof(v)) {
case TNull: false;