Skip to content

Conversation

@akarnokd
Copy link
Collaborator

Add the TakeUntil operator overload with a predicate that will complete the sequence after an item has been emitted and then the predicate returns true for it:

Observable.Range(1, 10)
   .TakeUntil(item => item == 5)
   .Subscribe(Console.WriteLine);

which prints 1 through 5 and completes.

There is a similar operator: TakeWhile which performs the check before the item is emitted.

This is one of the operators present in RxJava and mentioned in #489.

@danielcweber
Copy link
Collaborator

This is highly useful, we should just make sure the difference from TakeUntil(p) to TakeWhile(!p) is very clear.

@akarnokd
Copy link
Collaborator Author

Beyond the XML doc, I've tried to indicate with the stopPredicate naming that it is true that stops whereas in TakeWhile, false stops.

@danielcweber danielcweber merged commit ae8c989 into dotnet:master Jun 19, 2018
@akarnokd akarnokd deleted the TakeUntilPredicate branch June 21, 2018 09:34
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.

2 participants