Skip to content

Instantly share code, notes, and snippets.

@edubskiy
Last active July 12, 2020 11:53
Show Gist options
  • Save edubskiy/d0448f53761d44700f768be42b38975a to your computer and use it in GitHub Desktop.
Save edubskiy/d0448f53761d44700f768be42b38975a to your computer and use it in GitHub Desktop.
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