1 import { Observable } from '../Observable';
2 import { OperatorFunction } from '../types';
4 * Counts the number of emissions on the source and emits that number when the
7 * <span class="informal">Tells how many values were emitted, when the source
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`.
23 * Counts how many seconds have passed before the first click happened
25 * import { fromEvent, interval } from 'rxjs';
26 * import { count, takeUntil } from 'rxjs/operators';
28 * const seconds = interval(1000);
29 * const clicks = fromEvent(document, 'click');
30 * const secondsBeforeClick = seconds.pipe(takeUntil(clicks));
31 * const result = secondsBeforeClick.pipe(count());
32 * result.subscribe(x => console.log(x));
35 * Counts how many odd numbers are there between 1 and 7
37 * import { range } from 'rxjs';
38 * import { count } from 'rxjs/operators';
40 * const numbers = range(1, 7);
41 * const result = numbers.pipe(count(i => i % 2 === 1));
42 * result.subscribe(x => console.log(x));
51 * @param {function(value: T, i: number, source: Observable<T>): boolean} [predicate] A
52 * boolean function to select what values are to be counted. It is provided with
54 * - `value`: the value from the source Observable.
55 * - `index`: the (zero-based) "index" of the value from the source Observable.
56 * - `source`: the source Observable instance itself.
57 * @return {Observable} An Observable of one number that represents the count as
62 export declare function count<T>(predicate?: (value: T, index: number, source: Observable<T>) => boolean): OperatorFunction<T, number>;