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

Change Lift to use rx.Observable.Operator #857

Merged
merged 1 commit into from
Feb 12, 2014

Conversation

benjchristensen
Copy link
Member

The generics insanity has to stop.

This pull request is a result of @abersnaze and I continuing to fail to make generics work with this signature:

Func1<Subscriber<? super R>, Subscriber<? super T>>

It all fell apart while trying to do things that needed the equivalent of:

Func1<Subscriber<? super R>, Subscriber<? super ? super T>>

... and other such variants.

With this change I can also finally get the OperatorMerge generics to work.

Thus, the Operator type exists inside Observable just like OnSubscribe like this:

    /**
     * Operator function for lifting into an Observable.
     */
    public interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
        // cover for generics insanity
    }

This gives us imports like this:

import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Observable.Operator;

I know it's not as pure as having lift(Func1) but this is far more usable.

public <R> Observable<R> lift(final Operator<R, T> bind)

If anyone has a different suggestion that still solves the generics issue please let me know.

The generics insanity has to stop.
@benjchristensen
Copy link
Member Author

If you doubt the insanity, here's an error message for the merge operator :-)

The method lift(Func1<Subscriber<? super R>,Subscriber<? super capture#210-of ? extends Observable<? extends T>>>) in the type Observable<capture#210-of ? extends Observable<? extends T>> is not applicable for the arguments (OperatorMerge)

@benjchristensen
Copy link
Member Author

Apparently only the IDE likes merge now ... curse generics.

/Users/bechristensen/development/github/RxJavaFork/rxjava-core/src/main/java/rx/Observable.java:1780: error: method lift in class Observable<T#1> cannot be applied to given types;
        return source.lift(new OperatorMerge<T>());
                     ^
  required: Operator<R,CAP#1>
  found: OperatorMerge<T#2>
  reason: no instance(s) of type variable(s) R exist so that argument type OperatorMerge<T#2> conforms to formal parameter type Operator<R,CAP#1>
  where R,T#1,T#2 are type-variables:
    R extends Object declared in method <R>lift(Operator<R,T#1>)
    T#1 extends Object declared in class Observable
    T#2 extends Object declared in method <T#2>merge(Observable<? extends Observable<? extends T#2>>)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Observable<? extends T#2> from capture of ? extends Observable<? extends T#2>

benjchristensen added a commit that referenced this pull request Feb 12, 2014
Change Lift to use rx.Observable.Operator
@benjchristensen benjchristensen merged commit 55a7984 into ReactiveX:master Feb 12, 2014
@cloudbees-pull-request-builder

RxJava-pull-requests #782 SUCCESS
This pull request looks good

@benjchristensen
Copy link
Member Author

After fixing generics, it actually would be:

public <R> Observable<R> lift(final Func1<? extends Subscriber<? super R>, ? super Subscriber<? super T>> bind)

Using the Operator type it is instead:

public <R> Observable<R> lift(final Operator<? extends R, ? super T> bind)

as the type gives cover for:

public interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>>

@benjchristensen benjchristensen deleted the operator-type branch February 12, 2014 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants