Skip to content

Instantly share code, notes, and snippets.

@hobroker
Created August 23, 2020 18:52
Show Gist options
  • Save hobroker/96c6baea35ee00aecc85606a6cd0df93 to your computer and use it in GitHub Desktop.
Save hobroker/96c6baea35ee00aecc85606a6cd0df93 to your computer and use it in GitHub Desktop.
ofType Stream extension
import 'dart:async';
import 'package:stream_transform/src/from_handlers.dart';
extension OfType<T> on Stream<T> {
Stream<T> ofType<ActionType>() {
return transform(fromHandlers(
handleData: (element, sink) {
if (element is ActionType) {
sink.add(element);
}
},
handleDone: (sink) {
sink.close();
},
handleError: (error, stackTrace, sink) {
sink.addError(error, stackTrace);
},
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment