skip to content

takeWhile

 

takeWhile(predicate) will emit values from source while they satisfy given predicate, and will complete once emitted value dissatisfies the predicate:

1
2
3
4
5
6
7
8
9
10
11
12
const { rxObserver } = require('api/v0.3');
const { timer } = require('rxjs');
const { takeWhile } = require('rxjs/operators');

const source$ = timer(0, 100);

source$.subscribe(rxObserver('source$'));
source$.pipe(
    takeWhile(n => n < 5)
  )
  .subscribe(rxObserver('takeWhile(n < 5)'));
⚠️ Execution time is limited to 1000ms
0mssource$start00 11 22 33 44 55 66 77 88 99 1010 takeWhile(n < 5)startcomplete00 11 22 33 44

Also see take and takeUntil operators