PATH:
usr
/
local
/
lib
/
node_modules
/
ghost-cli
/
node_modules
/
rxjs
/
src
/
internal
/
operators
import { Observable } from '../Observable'; import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { EmptyError } from '../util/EmptyError'; import { OperatorFunction } from '../../internal/types'; import { filter } from './filter'; import { take } from './take'; import { defaultIfEmpty } from './defaultIfEmpty'; import { throwIfEmpty } from './throwIfEmpty'; import { identity } from '../util/identity'; /* tslint:disable:max-line-length */ export function first<T, D = T>( predicate?: null, defaultValue?: D ): OperatorFunction<T, T | D>; export function first<T, S extends T>( predicate: (value: T, index: number, source: Observable<T>) => value is S, defaultValue?: S ): OperatorFunction<T, S>; export function first<T, D = T>( predicate: (value: T, index: number, source: Observable<T>) => boolean, defaultValue?: D ): OperatorFunction<T, T | D>; /* tslint:enable:max-line-length */ /** * Emits only the first value (or the first value that meets some condition) * emitted by the source Observable. * * <span class="informal">Emits only the first value. Or emits only the first * value that passes some test.</span> * *  * * If called with no arguments, `first` emits the first value of the source * Observable, then completes. If called with a `predicate` function, `first` * emits the first value of the source that matches the specified condition. It * may also take a deprecated `resultSelector` function to produce the output * value from the input value, and a `defaultValue` to emit in case the source * completes before it is able to emit a valid value. Throws an error if * `defaultValue` was not provided and a matching element is not found. * * ## Examples * Emit only the first click that happens on the DOM * ```ts * import { fromEvent } from 'rxjs'; * import { first } from 'rxjs/operators'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(first()); * result.subscribe(x => console.log(x)); * ``` * * Emits the first click that happens on a DIV * ```ts * import { fromEvent } from 'rxjs'; * import { first } from 'rxjs/operators'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(first(ev => ev.target.tagName === 'DIV')); * result.subscribe(x => console.log(x)); * ``` * * @see {@link filter} * @see {@link find} * @see {@link take} * * @throws {EmptyError} Delivers an EmptyError to the Observer's `error` * callback if the Observable completes before any `next` notification was sent. * * @param {function(value: T, index: number, source: Observable<T>): boolean} [predicate] * An optional function called with each item to test for condition matching. * @param {R} [defaultValue] The default value emitted in case no valid value * was found on the source. * @return {Observable<T|R>} An Observable of the first item that matches the * condition. * @method first * @owner Observable */ export function first<T, D>( predicate?: ((value: T, index: number, source: Observable<T>) => boolean) | null, defaultValue?: D ): OperatorFunction<T, T | D> { const hasDefaultValue = arguments.length >= 2; return (source: Observable<T>) => source.pipe( predicate ? filter((v, i) => predicate(v, i, source)) : identity, take(1), hasDefaultValue ? defaultIfEmpty<T | D>(defaultValue) : throwIfEmpty(() => new EmptyError()), ); }
[-] toArray.ts
[edit]
[-] window.ts
[edit]
[-] retry.ts
[edit]
[-] mergeAll.ts
[edit]
[-] windowWhen.ts
[edit]
[-] every.ts
[edit]
[-] timeout.ts
[edit]
[-] debounceTime.ts
[edit]
[-] index.ts
[edit]
[-] takeWhile.ts
[edit]
[-] audit.ts
[edit]
[-] reduce.ts
[edit]
[-] mapTo.ts
[edit]
[-] count.ts
[edit]
[-] debounce.ts
[edit]
[-] throwIfEmpty.ts
[edit]
[-] auditTime.ts
[edit]
[-] scan.ts
[edit]
[-] switchAll.ts
[edit]
[-] map.ts
[edit]
[-] bufferCount.ts
[edit]
[-] mergeScan.ts
[edit]
[-] publish.ts
[edit]
[-] min.ts
[edit]
[+]
..
[-] publishReplay.ts
[edit]
[-] bufferTime.ts
[edit]
[-] share.ts
[edit]
[-] repeat.ts
[edit]
[-] distinct.ts
[edit]
[-] concatMapTo.ts
[edit]
[-] buffer.ts
[edit]
[-] concatMap.ts
[edit]
[-] max.ts
[edit]
[-] partition.ts
[edit]
[-] observeOn.ts
[edit]
[-] bufferWhen.ts
[edit]
[-] dematerialize.ts
[edit]
[-] throttle.ts
[edit]
[-] groupBy.ts
[edit]
[-] withLatestFrom.ts
[edit]
[-] exhaust.ts
[edit]
[-] exhaustMap.ts
[edit]
[-] retryWhen.ts
[edit]
[-] zipAll.ts
[edit]
[-] find.ts
[edit]
[-] mergeMap.ts
[edit]
[-] single.ts
[edit]
[-] last.ts
[edit]
[-] combineLatest.ts
[edit]
[-] publishLast.ts
[edit]
[-] pluck.ts
[edit]
[-] pairwise.ts
[edit]
[-] distinctUntilChanged.ts
[edit]
[-] timeInterval.ts
[edit]
[-] shareReplay.ts
[edit]
[-] skipUntil.ts
[edit]
[-] findIndex.ts
[edit]
[-] windowToggle.ts
[edit]
[-] startWith.ts
[edit]
[-] timeoutWith.ts
[edit]
[-] concat.ts
[edit]
[-] materialize.ts
[edit]
[-] timestamp.ts
[edit]
[-] onErrorResumeNext.ts
[edit]
[-] subscribeOn.ts
[edit]
[-] takeUntil.ts
[edit]
[-] skipLast.ts
[edit]
[-] throttleTime.ts
[edit]
[-] mergeMapTo.ts
[edit]
[-] multicast.ts
[edit]
[-] merge.ts
[edit]
[-] takeLast.ts
[edit]
[-] delayWhen.ts
[edit]
[-] sampleTime.ts
[edit]
[-] tap.ts
[edit]
[-] take.ts
[edit]
[-] sample.ts
[edit]
[-] filter.ts
[edit]
[-] skip.ts
[edit]
[-] expand.ts
[edit]
[-] publishBehavior.ts
[edit]
[-] sequenceEqual.ts
[edit]
[-] ignoreElements.ts
[edit]
[-] catchError.ts
[edit]
[-] endWith.ts
[edit]
[-] refCount.ts
[edit]
[-] windowCount.ts
[edit]
[-] defaultIfEmpty.ts
[edit]
[-] windowTime.ts
[edit]
[-] switchMapTo.ts
[edit]
[-] switchMap.ts
[edit]
[-] delay.ts
[edit]
[-] bufferToggle.ts
[edit]
[-] repeatWhen.ts
[edit]
[-] concatAll.ts
[edit]
[-] first.ts
[edit]
[-] zip.ts
[edit]
[-] elementAt.ts
[edit]
[-] skipWhile.ts
[edit]
[-] race.ts
[edit]
[-] finalize.ts
[edit]
[-] combineAll.ts
[edit]
[-] distinctUntilKeyChanged.ts
[edit]
[-] isEmpty.ts
[edit]