takeWhile

signature: takeWhile(predicate: function(value, index): boolean): Observable

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

  • :newspaper: - Official docs