Created
April 6, 2026 12:12
-
-
Save phyowaikyaw-mobiledev/08aaa5447cedcbfa5b002b74f983af09 to your computer and use it in GitHub Desktop.
Assignment 20 - Stream with Custom StreamTransformer
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
| import 'dart:async'; | |
| Stream<dynamic> emit() async* { | |
| yield 1; | |
| yield 'hello'; | |
| yield 2; | |
| yield 'world'; | |
| yield 3; | |
| } | |
| class FilterInt extends StreamTransformerBase<dynamic, int> { | |
| @override | |
| Stream<int> bind(Stream<dynamic> stream) { | |
| return stream.where((event) => event is int).cast<int>(); | |
| } | |
| } | |
| void main() async { | |
| await for (final value in emit().transform(FilterInt())) { | |
| print(value); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment