-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 TakeUntil operation #151
Conversation
This is a very elegant solution. I wouldn't have considered using the Pair with map/merge/takeWhile like that. The only thing I'd like to add is an instance version: public <E> Observable<T> takeUntil(final Observable<E> other) This way I can chain off an Observable I already have instead of only statically. |
What about having |
@prabirshrestha that's a good thought, I've considered it but been holding off for the following reasons:
For example, Groovy and Closure generally prefer arrays/sequence of values without strong typing and typically just return something simple like [a, b]. I probably should have noted in this review that it would be best to not put Pair in rx.util but keep it private (inner class perhaps) until nailing down those questions above. |
Do you want to implement the instance method of takeUntil and re-submit, or do you want me to just add that myself? Based on the previous question/comment as well I think Pair needs to be kept private for now until decisions on Tuple are made. What do you think about moving the implementation into an OperationTakeUntil class so that Observable doesn't keep growing huge? Since we lack extensions methods in Java we have to put all the static and instance methods in there, but we can extract implementation details and their testing into Operation* classes to try and keep some sanity. |
@benjchristensen thank you for the review. I'll update the pull request. |
You may want to start a new pull request on a new updated branch as this no longer can merge without conflicts. |
Conflicts: rxjava-core/src/main/java/rx/Observable.java
Seems like code doesn't handle all cases. When To be precise following test fails @Test
public void testTakeUntilCompleted() {
Subscription sSource = mock(Subscription.class);
Subscription sOther = mock(Subscription.class);
TestObservable source = new TestObservable(sSource);
TestObservable other = new TestObservable(sOther);
Observer<String> result = mock(Observer.class);
Observable<String> stringObservable = takeUntil(source, other);
stringObservable.subscribe(result);
source.sendOnNext("one");
source.sendOnNext("two");
source.sendOnCompleted();
verify(result, times(1)).onNext("one");
verify(result, times(1)).onNext("two");
verify(sSource, times(1)).unsubscribe();
verify(sOther, times(1)).unsubscribe();
} I'll update the code to handle this use case. |
I modified |
RxJava-pull-requests #5 SUCCESS |
@teyc you are right, I'll update the code. Thank you! |
RxJava-pull-requests #12 SUCCESS |
RxJava-pull-requests #13 SUCCESS |
Based on my reading of the code, MSDN docs and the unit tests this looks good. Merging ... |
Implemented TakeUntil operation
Implemented TakeUntil operation
Fixes issue #86