Froussios / Intro-To-RxJava

An extensive tutorial on RxJava
2.05k stars 400 forks source link

Example with 'sequenceEqual' operator is wrong #30

Closed piotrek1543 closed 7 years ago

piotrek1543 commented 7 years ago

Hi,

going through your excellent tutorial I I've already noticed that I cannot write a function like this:

Observable.sequenceEqual(strings, ints, (s,i) -> s.equals(i.toString()))
//Observable.sequenceEqual(strings, ints)
    .subscribe(
        v -> System.out.println(v),
        e -> System.out.println("Error: " + e),
        () -> System.out.println("Completed")
    );

The working version should be like this:

Subscription sequenceEqual = Observable.sequenceEqual(
        just1, just2, (s, i) -> s.equals(just1.toString())).subscribe();

where declarations of just1 and `just2' variables:

 Observable<Integer> just1 = Observable.just(1, 2, 3);
 Observable<String> just2 = Observable.just("1", "2", "3");

Did you forgot to declare a variable or it changed with newer version of RxJava?

I'm using this dependencies:

compile 'io.reactivex:rxjava:1.1.1'
compile 'io.reactivex:rxandroid:1.1.0'

Cheers

Froussios commented 7 years ago

I don't understand what the difference is in the changed example. Can you elaborate?

Froussios commented 7 years ago

Why not use strings and ints as they are declared in the example? The associated .java file also seems to work without problem.

piotrek1543 commented 7 years ago

@Froussios Well, the problem was that I couldn't use

        Observable.sequenceEqual(strings, ints, (s,i) -> s.equals(i.toString()))

without declaration of Subscription like:

        Subscription sequenceEqual = Observable.sequenceEqual(...)

Every time I tried to compile it, it returned an error. As you may noticed I used

     compile 'io.reactivex:rxjava:1.1.1'

Now I changed dependency to compile 'io.reactivex:rxjava:1.2.1' and it works without this disused decraration like:

        Subscription sequenceEqual = ...

Strange, maybe there was another 'typo' issue which I missed or that version of library was corrupted.

Nevermind. Now it works fine.

Thanks for response.