Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the 'cast' and 'ofType' operators #403

Merged
merged 6 commits into from
Sep 25, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4332,6 +4332,23 @@ public BlockingObservable<T> toBlockingObservable() {
return BlockingObservable.from(this);
}

/**
* Converts the elements of an observable sequence to the specified type.
*
* @return An observable sequence that contains each element of the source
* sequence converted to the specified type.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211842(v=vs.103).aspx">MSDN: Observable.Cast</a>
*/
public <R> Observable<R> cast() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this signature should be Observable<R> cast(Class<R> klass). Then you can use klass.cast(t) and won't need to suppress unchecked warnings. Also, it will mean that a ClassCastException will be generated here rather than at some random place downstream.

My signature will need to be adjusted by the co/contra-variance police, of course :)

return map(new Func1<T, R>() {
@SuppressWarnings("unchecked")
public R call(T t) {
return (R) t;
}
});
}

/**
* Whether a given {@link Function} is an internal implementation inside rx.* packages or not.
* <p>
Expand Down