Last active
June 14, 2021 01:28
-
-
Save codetricity/ef386fa4949dd5513e7c3705dd021eb1 to your computer and use it in GitHub Desktop.
Basic Dart Stream example
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 { | |
Stream<String> sushi = Stream<String>.periodic(Duration(seconds: 1), (x) => '$x: fish').take(10); | |
var mappedSushi = sushi.map((sushiPiece) => sushiPiece + ' mapped'); | |
await mappedSushi.forEach( print); | |
} | |
/* output | |
0: fish mapped | |
1: fish mapped | |
2: fish mapped | |
3: fish mapped | |
4: fish mapped | |
5: fish mapped | |
6: fish mapped | |
7: fish mapped | |
8: fish mapped | |
9: fish mapped | |
*/ | |
/* run code on dart pad | |
https://dartpad.dev/ef386fa4949dd5513e7c3705dd021eb1?null_safety=true | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment