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 TakeUntil operation #151

Merged
merged 7 commits into from
Mar 11, 2013

Conversation

mairbek
Copy link
Contributor

@mairbek mairbek commented Feb 19, 2013

Fixes issue #86

@benjchristensen
Copy link
Member

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.

@prabirshrestha
Copy link
Contributor

What about having Tuple2<A, B>, Tuple3<A,B,C> and so on like func and actions instead of using Pair<A, B>?
Even ReactiveCocoa has RACTuple.

@benjchristensen
Copy link
Member

@prabirshrestha that's a good thought, I've considered it but been holding off for the following reasons:

  1. We haven't had an operator yet need them so didn't want to eagerly add them until actually needed.
  2. How will they work with each of the languages? Will they be idiomatic or awkward? Perhaps we can be typed but also implement Iterable and List so they can be accessed dynamically like an array rather than via fields/accessors.
  3. Will these duplicate/collide with anything coming in Java8 and if so can be future-proof by matching the signature and then being able to extend from those interface when they arrive?

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.

@benjchristensen
Copy link
Member

@mairbek

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.

@mairbek
Copy link
Contributor Author

mairbek commented Feb 27, 2013

@benjchristensen thank you for the review. I'll update the pull request.

@benjchristensen
Copy link
Member

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
@mairbek
Copy link
Contributor Author

mairbek commented Mar 4, 2013

Seems like code doesn't handle all cases.

When source observable completes, observer should unsubscribe immediately.

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.

@mairbek
Copy link
Contributor Author

mairbek commented Mar 4, 2013

I modified TakeUntil a bit. It's not as elegant as it was before, but it still uses merge operation to avoid dealing with concurrency. And it works correctly :) (more unit tests passed).

@cloudbees-pull-request-builder

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

@mairbek
Copy link
Contributor Author

mairbek commented Mar 10, 2013

@teyc you are right, I'll update the code.

Thank you!

@cloudbees-pull-request-builder

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

@cloudbees-pull-request-builder

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

@benjchristensen
Copy link
Member

Based on my reading of the code, MSDN docs and the unit tests this looks good. Merging ...

benjchristensen added a commit that referenced this pull request Mar 11, 2013
@benjchristensen benjchristensen merged commit 9c6dec9 into ReactiveX:master Mar 11, 2013
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
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.

5 participants