Created
January 19, 2019 20:31
-
-
Save gabrc52/0e5a3ff7daff4be34a415bc0d6494ecc to your computer and use it in GitHub Desktop.
Python-like range function in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Iterable<int> range(int start, [int stop, int increment]) sync* { | |
if (increment == null) { | |
increment = 1; | |
} | |
if (stop == null) { | |
stop = start; | |
start = 0; | |
} | |
for (int i = start; start < stop ? i < stop : i > stop; i += increment) { | |
yield i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment