Skip to content

Instantly share code, notes, and snippets.

@armando-couto
Last active March 9, 2020 00:50
Show Gist options
  • Save armando-couto/f25db0272994b247d869b804031154a2 to your computer and use it in GitHub Desktop.
Save armando-couto/f25db0272994b247d869b804031154a2 to your computer and use it in GitHub Desktop.
Iterable<int> countTo(int max) sync {
int i = 0;
while(i < max) yield i++;
}
main() {
Iterable it = countTo(5);
Iterable i = it.iterator;
while (i.moveNext()) {
print(i.current);
}
}
Stream<int> countTo(int max) async* {
int i = 0;
while(i < max) yield i++;
}
main() async {
Stream s countTo(5);
await for (int i in s) { print(i); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment