takeWhile.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { MonoTypeOperatorFunction } from '../interfaces';
  2. /**
  3. * Emits values emitted by the source Observable so long as each value satisfies
  4. * the given `predicate`, and then completes as soon as this `predicate` is not
  5. * satisfied.
  6. *
  7. * <span class="informal">Takes values from the source only while they pass the
  8. * condition given. When the first value does not satisfy, it completes.</span>
  9. *
  10. * <img src="./img/takeWhile.png" width="100%">
  11. *
  12. * `takeWhile` subscribes and begins mirroring the source Observable. Each value
  13. * emitted on the source is given to the `predicate` function which returns a
  14. * boolean, representing a condition to be satisfied by the source values. The
  15. * output Observable emits the source values until such time as the `predicate`
  16. * returns false, at which point `takeWhile` stops mirroring the source
  17. * Observable and completes the output Observable.
  18. *
  19. * @example <caption>Emit click events only while the clientX property is greater than 200</caption>
  20. * var clicks = Rx.Observable.fromEvent(document, 'click');
  21. * var result = clicks.takeWhile(ev => ev.clientX > 200);
  22. * result.subscribe(x => console.log(x));
  23. *
  24. * @see {@link take}
  25. * @see {@link takeLast}
  26. * @see {@link takeUntil}
  27. * @see {@link skip}
  28. *
  29. * @param {function(value: T, index: number): boolean} predicate A function that
  30. * evaluates a value emitted by the source Observable and returns a boolean.
  31. * Also takes the (zero-based) index as the second argument.
  32. * @return {Observable<T>} An Observable that emits the values from the source
  33. * Observable so long as each value satisfies the condition defined by the
  34. * `predicate`, then completes.
  35. * @method takeWhile
  36. * @owner Observable
  37. */
  38. export declare function takeWhile<T>(predicate: (value: T, index: number) => boolean): MonoTypeOperatorFunction<T>;