Skip to content

Instantly share code, notes, and snippets.

@codetricity
Last active June 14, 2021 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codetricity/ef386fa4949dd5513e7c3705dd021eb1 to your computer and use it in GitHub Desktop.
Save codetricity/ef386fa4949dd5513e7c3705dd021eb1 to your computer and use it in GitHub Desktop.
Basic Dart Stream example
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