Created
August 23, 2020 18:52
-
-
Save hobroker/96c6baea35ee00aecc85606a6cd0df93 to your computer and use it in GitHub Desktop.
ofType Stream extension
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'; | |
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