mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
15 lines
390 B
Dart
15 lines
390 B
Dart
extension IntExtension on int {
|
|
Iterable<int> until(int to, [int step = 1]) sync* {
|
|
if (step == 0) {
|
|
throw ArgumentError("step must not be zero");
|
|
}
|
|
final sign = (to - this).sign;
|
|
if (sign != step.sign) {
|
|
// e.g., 0.until(10, -1) or 0.until(-10, 1)
|
|
return;
|
|
}
|
|
for (var i = this; sign > 0 ? i < to : i > to; i += step) {
|
|
yield i;
|
|
}
|
|
}
|
|
}
|