This is the last operator from the take() family we will see in this chapter. This operator lets you create an observable from the first contiguous sequence of elements in an observable satisfying a given conditional function. It has the following signature:
The first parameter is mandatory and the last is optional:
- condition: This is a given function which the elements must satisfy
- context: This argument is used in the conditional function
We can use this operator to take the first contiguous sequence of even numbers, as can be seen in the following example:
Rx.Observable .of(2,4,5,6) .takeWhile((i)=>i%2===0) .subscribe((i)=>console.log(i));
In this code, we will ...