I have a RxJS5 pipeline looks like this
Rx.Observable.from([2, 3, 4, 5, 6])
.takeWhile((v) => { v !== 4 })
I want to keep the subscription until I see 4, but I want to last element 4 also to be included in the result. So the example above should be
2, 3, 4
However, according to official document, takeWhile
operator is not inclusive. Which means when it encounters the element which doesn't match predicate we gave, it completes the stream immediately without the last element. As a result, the above code will actually output
2, 3
So my question is, what's the easiest way I can achieve takeWhile
but also emit the last element with RxJS?
.takeWhile(v => v < 5)
– SchutttakeUntil
method which takes a predicate. The difference withtakeWhile
is that it does include the last item. – Smoothspoken