Skip to content

Instantly share code, notes, and snippets.

@bfritscher
Created September 11, 2023 12:29
Show Gist options
  • Save bfritscher/3543f71324a48f2756279d0d4eb9b8a7 to your computer and use it in GitHub Desktop.
Save bfritscher/3543f71324a48f2756279d0d4eb9b8a7 to your computer and use it in GitHub Desktop.
dart-streams
void main() async {
var stream = countStream(10);
print(stream);
stream.listen((value) {
print(value);
});
print("after stream");
stream = countStream(10);
await for (final value in stream) {
print(value);
}
print("after await");
stream = countStream(10);
var transformedStream = stream.where((x) => x % 2 == 0);
await for (final value in transformedStream) {
print(value);
}
print("after await2");
stream = countStream(10);
print(await stream.where((x) => x % 2 == 0).join(':'));
}
Stream<int> countStream(int to) async* {
for (int i = 1; i <= to; i++) {
yield i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment