Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

count.d.ts 2.2KB

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