Search code examples
rx-javareactivex

How to emmit the last element ussing takeWhile?


I have stream that emits items since an element. I know which element is. Once that element is emmited the stream doesn't emit more. The problem is that it doesn't emmit the onComplete. I need something more less like takeWhile but emmiting the last element too. This is the idea with marbles:

Take whileish

(Original image extracted from ReactiveX TakeWhile)

Which operator or operators can I use to do this?


Solution

  • Just repeating my comment:

    The operator is called takeUntil with a Func1<T, Boolean> predicate parameter:

    http://reactivex.io/RxJava/javadoc/rx/Observable.html#takeUntil(rx.functions.Func1)