-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
library rx.operators.where_type; | ||
|
||
import 'package:rx/src/core/observer.dart'; | ||
import 'package:rx/src/core/operator.dart'; | ||
import 'package:rx/src/core/subscriber.dart'; | ||
|
||
/// Filter items emitted by the source Observable by only emitting those that | ||
/// are of the specified type. | ||
OperatorFunction<T, R> whereType<T, R>() => | ||
(source) => source.lift<R>((source, subscriber) => | ||
source.subscribe(_WhereTypeSubscriber<T, R>(subscriber))); | ||
|
||
class _WhereTypeSubscriber<T, R> extends Subscriber<T> { | ||
_WhereTypeSubscriber(Observer<R> destination) : super(destination); | ||
|
||
@override | ||
void onNext(T value) { | ||
if (value is R) { | ||
doNext(value); | ||
} | ||
} | ||
} |
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