Skip to content

Different behaviors of SequenceEqual in Rx.Net and RxJava #564

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

Closed
zsxwing opened this issue Dec 5, 2013 · 3 comments
Closed

Different behaviors of SequenceEqual in Rx.Net and RxJava #564

zsxwing opened this issue Dec 5, 2013 · 3 comments

Comments

@zsxwing
Copy link
Member

zsxwing commented Dec 5, 2013

Looks SequenceEqual in Rxjava is not correct.

In Rx.Net, SequenceEqual returns an Observable which only has one element indicating if these two sequences are same. For example,

            var o = Observable.SequenceEqual(Observable.Range(1, 100), Observable.Range(1, 100));
            var s = o.Subscribe(
                v => Console.WriteLine("Equal = " + v),
                e =>  Console.WriteLine(e),
                () => Console.WriteLine("onCompleted")
                );
            Console.WriteLine("Press any key...");
            Console.ReadKey();

Outputs:

Equal = True
onCompleted
Press any key...

But in RxJava, the following codes:

        Observable
                .sequenceEqual(Observable.range(1, 100),
                        Observable.range(1, 100)).toBlockingObservable()
                .forEach(new Action1<Boolean>() {
                    @Override
                    public void call(Boolean t1) {
                        System.out.println(t1);
                    }
                });

Output 100 trues.

@akarnokd
Copy link
Member

akarnokd commented Dec 5, 2013

I've noticed that using zip to pair up values is not the same behavior as in Rx.NET. In Rx.NET, the operator checks if the length of the streams are the same or not. Even if we don't want to do that, one could add a simple all operator after the zip:

public static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> first, 
        Observable<? extends T> second, Func2<? super T, ? super T, Boolean> equality) {
    return zip(first, second, equality).all(Functions.<Boolean>identity());
}

Using the materialized view is not an option as errors need to be propagated directly and not compared (and generally, equals doesn't work on Throwables).

@zsxwing
Copy link
Member Author

zsxwing commented Dec 6, 2013

I can take this this weekend.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 9, 2013

fixed in #575

@zsxwing zsxwing closed this as completed Dec 9, 2013
jihoonson pushed a commit to jihoonson/RxJava that referenced this issue Mar 6, 2020
… support … (ReactiveX#564)

* Issue ReactiveX#547: Adapted CircuitBreakerConfigurationProperties to support the new sliding window types.
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

No branches or pull requests

2 participants