Created with <3 with dartpad.dev.
Created
September 11, 2023 12:29
-
-
Save bfritscher/3543f71324a48f2756279d0d4eb9b8a7 to your computer and use it in GitHub Desktop.
dart-streams
This file contains hidden or 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
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