Last active
July 12, 2020 11:53
-
-
Save edubskiy/d0448f53761d44700f768be42b38975a to your computer and use it in GitHub Desktop.
This file contains 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'; | |
class Cake { | |
} | |
class Order { | |
String type; | |
Order(this.type); | |
} | |
void main() { | |
final controller = new StreamController(); | |
final order = new Order('chocolate'); | |
final baker = new StreamTransformer.fromHandlers( | |
handleData: (cakeType, sink) { | |
if (cakeType == 'chocolate') { | |
sink.add(new Cake()); | |
} else { | |
sink.addError('I can not bake that type: $cakeType'); | |
} | |
} | |
); | |
controller.sink.add(order); | |
controller.stream | |
.map((order) { | |
return order.type; | |
}) | |
.transform(baker) | |
.listen( | |
(cake) => print('Here is your $cake'), | |
onError: (error) => print(error) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment