takeWhile
signature: takeWhile(predicate: function(value, index): boolean): Observable
Example 1: Take values under limit
Example 2: Difference between takeWhile() and filter()
import { of } from 'rxjs/observable/of';
// emit 3, 3, 3, 9, 1, 4, 5, 8, 96, 3, 66, 3, 3, 3
// allow values until value from source equals 3, then complete
// output: [3, 3, 3]
source
.pipe(takeWhile(it => it === 3))
// output: [3, 3, 3, 3, 3, 3, 3]
source
.pipe(filter(it => it === 3))
- Official docs