Skip to content

Commit

Permalink
Merge pull request #1778 from zsxwing/compose
Browse files Browse the repository at this point in the history
Change Transformer to Func1<Observable<T>, Observable<R>>
  • Loading branch information
benjchristensen committed Oct 20, 2014
2 parents a1aca70 + 5bba1c9 commit c9558b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,15 @@ public void call(Subscriber<? super R> o) {
* @return the source Observable, transformed by the transformer function
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a>
*/
@SuppressWarnings("unchecked")
public <R> Observable<R> compose(Transformer<? super T, ? extends R> transformer) {
// Casting to Observable<R> is type-safe because we know Observable is covariant.
return (Observable<R>) ((Transformer<T, ? extends R>) transformer).call(this);
return ((Transformer<T, R>) transformer).call(this);
}

/**
* Transformer function used by {@link #compose}.
* @warn more complete description needed
*/
public static interface Transformer<T, R> extends Func1<Observable<T>, Observable<? extends R>> {
public static interface Transformer<T, R> extends Func1<Observable<T>, Observable<R>> {
// cover for generics insanity
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/rx/CovarianceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Observable<String> call(GroupedObservable<Class<? extends Movie>, Movie>
return g.compose(new Transformer<Movie, Movie>() {

@Override
public Observable<? extends Movie> call(Observable<Movie> m) {
public Observable<Movie> call(Observable<Movie> m) {
return m.concatWith(Observable.just(new ActionMovie()));
}

Expand All @@ -112,7 +112,7 @@ public void testCovarianceOfCompose() {
Observable<Movie> movie2 = movie.compose(new Transformer<Movie, Movie>() {

@Override
public Observable<? extends Movie> call(Observable<Movie> t1) {
public Observable<Movie> call(Observable<Movie> t1) {
return Observable.just(new Movie());
}

Expand All @@ -124,7 +124,7 @@ public void testCovarianceOfCompose2() {
Observable<Movie> movie = Observable.<Movie> just(new HorrorMovie());
Observable<HorrorMovie> movie2 = movie.compose(new Transformer<Movie, HorrorMovie>() {
@Override
public Observable<? extends HorrorMovie> call(Observable<Movie> t1) {
public Observable<HorrorMovie> call(Observable<Movie> t1) {
return Observable.just(new HorrorMovie());
}
});
Expand All @@ -135,7 +135,7 @@ public void testCovarianceOfCompose3() {
Observable<Movie> movie = Observable.<Movie>just(new HorrorMovie());
Observable<HorrorMovie> movie2 = movie.compose(new Transformer<Movie, HorrorMovie>() {
@Override
public Observable<? extends HorrorMovie> call(Observable<Movie> t1) {
public Observable<HorrorMovie> call(Observable<Movie> t1) {
return Observable.just(new HorrorMovie()).map(new Func1<HorrorMovie, HorrorMovie>() {

@Override
Expand All @@ -152,7 +152,7 @@ public void testCovarianceOfCompose4() {
Observable<HorrorMovie> movie = Observable.just(new HorrorMovie());
Observable<HorrorMovie> movie2 = movie.compose(new Transformer<HorrorMovie, HorrorMovie>() {
@Override
public Observable<? extends HorrorMovie> call(Observable<HorrorMovie> t1) {
public Observable<HorrorMovie> call(Observable<HorrorMovie> t1) {
return t1.map(new Func1<HorrorMovie, HorrorMovie>() {

@Override
Expand Down

0 comments on commit c9558b4

Please sign in to comment.