Front end of the Slack clone application.

count.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { count as higherOrder } from '../operators/count';
  2. /**
  3. * Counts the number of emissions on the source and emits that number when the
  4. * source completes.
  5. *
  6. * <span class="informal">Tells how many values were emitted, when the source
  7. * completes.</span>
  8. *
  9. * <img src="./img/count.png" width="100%">
  10. *
  11. * `count` transforms an Observable that emits values into an Observable that
  12. * emits a single value that represents the number of values emitted by the
  13. * source Observable. If the source Observable terminates with an error, `count`
  14. * will pass this error notification along without emitting a value first. If
  15. * the source Observable does not terminate at all, `count` will neither emit
  16. * a value nor terminate. This operator takes an optional `predicate` function
  17. * as argument, in which case the output emission will represent the number of
  18. * source values that matched `true` with the `predicate`.
  19. *
  20. * @example <caption>Counts how many seconds have passed before the first click happened</caption>
  21. * var seconds = Rx.Observable.interval(1000);
  22. * var clicks = Rx.Observable.fromEvent(document, 'click');
  23. * var secondsBeforeClick = seconds.takeUntil(clicks);
  24. * var result = secondsBeforeClick.count();
  25. * result.subscribe(x => console.log(x));
  26. *
  27. * @example <caption>Counts how many odd numbers are there between 1 and 7</caption>
  28. * var numbers = Rx.Observable.range(1, 7);
  29. * var result = numbers.count(i => i % 2 === 1);
  30. * result.subscribe(x => console.log(x));
  31. *
  32. * // Results in:
  33. * // 4
  34. *
  35. * @see {@link max}
  36. * @see {@link min}
  37. * @see {@link reduce}
  38. *
  39. * @param {function(value: T, i: number, source: Observable<T>): boolean} [predicate] A
  40. * boolean function to select what values are to be counted. It is provided with
  41. * arguments of:
  42. * - `value`: the value from the source Observable.
  43. * - `index`: the (zero-based) "index" of the value from the source Observable.
  44. * - `source`: the source Observable instance itself.
  45. * @return {Observable} An Observable of one number that represents the count as
  46. * described above.
  47. * @method count
  48. * @owner Observable
  49. */
  50. export function count(predicate) {
  51. return higherOrder(predicate)(this);
  52. }
  53. //# sourceMappingURL=count.js.map