2022-05-29 09:24:36 +00:00
|
|
|
import { MonoTypeOperatorFunction } from '../types';
|
2022-01-21 08:28:41 +00:00
|
|
|
/**
|
|
|
|
* Emits the single value at the specified `index` in a sequence of emissions
|
|
|
|
* from the source Observable.
|
|
|
|
*
|
|
|
|
* <span class="informal">Emits only the i-th value, then completes.</span>
|
|
|
|
*
|
|
|
|
* ![](elementAt.png)
|
|
|
|
*
|
|
|
|
* `elementAt` returns an Observable that emits the item at the specified
|
|
|
|
* `index` in the source Observable, or a default value if that `index` is out
|
|
|
|
* of range and the `default` argument is provided. If the `default` argument is
|
|
|
|
* not given and the `index` is out of range, the output Observable will emit an
|
|
|
|
* `ArgumentOutOfRangeError` error.
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
* Emit only the third click event
|
|
|
|
* ```ts
|
2022-05-29 09:24:36 +00:00
|
|
|
* import { fromEvent } from 'rxjs';
|
|
|
|
* import { elementAt } from 'rxjs/operators';
|
2022-01-21 08:28:41 +00:00
|
|
|
*
|
|
|
|
* const clicks = fromEvent(document, 'click');
|
|
|
|
* const result = clicks.pipe(elementAt(2));
|
|
|
|
* result.subscribe(x => console.log(x));
|
|
|
|
*
|
|
|
|
* // Results in:
|
|
|
|
* // click 1 = nothing
|
|
|
|
* // click 2 = nothing
|
|
|
|
* // click 3 = MouseEvent object logged to console
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @see {@link first}
|
|
|
|
* @see {@link last}
|
|
|
|
* @see {@link skip}
|
|
|
|
* @see {@link single}
|
|
|
|
* @see {@link take}
|
|
|
|
*
|
|
|
|
* @throws {ArgumentOutOfRangeError} When using `elementAt(i)`, it delivers an
|
2022-05-29 09:24:36 +00:00
|
|
|
* ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0` or the
|
2022-01-21 08:28:41 +00:00
|
|
|
* Observable has completed before emitting the i-th `next` notification.
|
|
|
|
*
|
|
|
|
* @param {number} index Is the number `i` for the i-th source emission that has
|
|
|
|
* happened since the subscription, starting from the number `0`.
|
|
|
|
* @param {T} [defaultValue] The default value returned for missing indices.
|
2022-05-29 09:24:36 +00:00
|
|
|
* @return {Observable} An Observable that emits a single item, if it is found.
|
|
|
|
* Otherwise, will emit the default value if given. If not, then emits an error.
|
|
|
|
* @method elementAt
|
|
|
|
* @owner Observable
|
2022-01-21 08:28:41 +00:00
|
|
|
*/
|
2022-05-29 09:24:36 +00:00
|
|
|
export declare function elementAt<T>(index: number, defaultValue?: T): MonoTypeOperatorFunction<T>;
|