UNPKG

1.9 kBTypeScriptView Raw
1import { OperatorFunction } from '../types';
2/**
3 * Emits the single value at the specified `index` in a sequence of emissions
4 * from the source Observable.
5 *
6 * <span class="informal">Emits only the i-th value, then completes.</span>
7 *
8 * ![](elementAt.png)
9 *
10 * `elementAt` returns an Observable that emits the item at the specified
11 * `index` in the source Observable, or a default value if that `index` is out
12 * of range and the `default` argument is provided. If the `default` argument is
13 * not given and the `index` is out of range, the output Observable will emit an
14 * `ArgumentOutOfRangeError` error.
15 *
16 * ## Example
17 *
18 * Emit only the third click event
19 *
20 * ```ts
21 * import { fromEvent, elementAt } from 'rxjs';
22 *
23 * const clicks = fromEvent(document, 'click');
24 * const result = clicks.pipe(elementAt(2));
25 * result.subscribe(x => console.log(x));
26 *
27 * // Results in:
28 * // click 1 = nothing
29 * // click 2 = nothing
30 * // click 3 = MouseEvent object logged to console
31 * ```
32 *
33 * @see {@link first}
34 * @see {@link last}
35 * @see {@link skip}
36 * @see {@link single}
37 * @see {@link take}
38 *
39 * @throws {ArgumentOutOfRangeError} When using `elementAt(i)`, it delivers an
40 * ArgumentOutOfRangeError to the Observer's `error` callback if `i < 0` or the
41 * Observable has completed before emitting the i-th `next` notification.
42 *
43 * @param {number} index Is the number `i` for the i-th source emission that has
44 * happened since the subscription, starting from the number `0`.
45 * @param {T} [defaultValue] The default value returned for missing indices.
46 * @return A function that returns an Observable that emits a single item, if
47 * it is found. Otherwise, it will emit the default value if given. If not, it
48 * emits an error.
49 */
50export declare function elementAt<T, D = T>(index: number, defaultValue?: D): OperatorFunction<T, T | D>;
51//# sourceMappingURL=elementAt.d.ts.map
\No newline at end of file