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

Operator TakeUntil with predicate #2493

Merged
merged 3 commits into from
Feb 4, 2015

Conversation

akarnokd
Copy link
Member

Take values and check the condition after the value is emitted.

For enhancement request #1649.

@benjchristensen
Copy link
Member

Thanks for adding this! Not convinced on the name though. The 'do' prefix is used to represent side-effects everywhere else. I think the prefix should still be take-something.

@akarnokd akarnokd changed the title Operator DoTakeWhile Operator TakeUntil with predicate Jan 27, 2015
@akarnokd
Copy link
Member Author

The question then remains, should it stop if predicate turns into false or should it stop if predicate turns into true? Because, classically do { } while (true) and repeat until false (Pascal).

@benjchristensen
Copy link
Member

I like it how it's currently implemented ... do until true.

It fits the "takeUntil" term ... "take until a value == predicate".

        System.out.println("------------------------");
        Observable.just(1, 2, 3, 4, 5, 6, 7)
                .doOnEach(System.out::println)
                .takeUntil(i -> i == 3)
                .forEach(System.out::println);

        System.out.println("------------------------");
        Observable.just(1, 2, 3, 4, 5, 6, 7)
                .doOnEach(System.out::println)
                .takeWhile(i -> i <= 3)
                .forEach(System.out::println);

That code shows the difference with takeWhile and it works well. We emit 1, 2, 3 and then stop.

------------------------
[rx.Notification@891cd479 OnNext 1]
1
[rx.Notification@891cd47a OnNext 2]
2
[rx.Notification@891cd47b OnNext 3]
3
------------------------
[rx.Notification@891cd479 OnNext 1]
1
[rx.Notification@891cd47a OnNext 2]
2
[rx.Notification@891cd47b OnNext 3]
3
[rx.Notification@891cd47c OnNext 4]

benjchristensen added a commit that referenced this pull request Feb 4, 2015
@benjchristensen benjchristensen merged commit 1f08a67 into ReactiveX:1.x Feb 4, 2015
@benjchristensen benjchristensen added this to the 1.0.x milestone Feb 4, 2015
@akarnokd akarnokd deleted the OperatorDoTakeWhile branch May 6, 2015 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants