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 distinctUntilChanged operation #374

Merged
merged 4 commits into from
Sep 13, 2013

Conversation

jmhofer
Copy link
Contributor

@jmhofer jmhofer commented Sep 12, 2013

This is the implementation for distinctUntilChanged as described in #39.

I haven't implemented the two methods from .NET that are using an IEqualityComparator because I don't think it would be idiomatic Java to define an interface like this and use that here. - Or does somebody want that?

@cloudbees-pull-request-builder

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

@cloudbees-pull-request-builder

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

@abersnaze
Copy link
Contributor

What about a method that takes a java.util.Comparator?

@jmhofer
Copy link
Contributor Author

jmhofer commented Sep 12, 2013

@abersnaze I don't know. It's possible (and easy), of course. I just don't see much of a use case. But maybe that's just me.

@abersnaze
Copy link
Contributor

If there was an Observable of some object and they either didn't implement equals correctly or a different criteria for equality was needed then (in Java) this operator couldn't be used as is. I work around be to use map before to wrap the object that implements a different equals then a map after it to unwrap it.

@jmhofer
Copy link
Contributor Author

jmhofer commented Sep 12, 2013

You could also use the distinctUntilChanged version with the keySelector to work around that. Then there's not even the need for unwrapping anymore.

@abersnaze
Copy link
Contributor

The point I was trying to make was that I think it would be inconvenient and not in line with most of the other java APIs that involve comparing values.

This brings up another concern that I have is how to deal with instance operators that require some additional constraints on the values emitted. In this case it only works if equals is implemented correctly. Then there is the no arg version toSortedList() that casts the values to Comparable. Some of the other method only operate on Observable<Observable>. The only way to ensure that is to have them as static where the generics can be specific to that method. I thought about making a toComparableObservable(Comparator) where the sorting APIs could live or a toObservableOfObservable() where zip and merge could be instance methods. There are many problems with this idea.

  • discoverability of operators.
  • inability to mix sorted observable of observables.
  • it still isn't type safe.

@benjchristensen
Copy link
Member

I tend to agree that we should have the Comparator overloads, but those can be added later. Merging ...

benjchristensen added a commit that referenced this pull request Sep 13, 2013
Implemented distinctUntilChanged operation
@benjchristensen benjchristensen merged commit 7217232 into ReactiveX:master Sep 13, 2013
@jmhofer jmhofer deleted the distinctUntilChanged branch September 13, 2013 06:47
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
Implemented distinctUntilChanged operation
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.

4 participants