From 56e31e921fe6c63b61bb4fe875d0b8c75617fc69 Mon Sep 17 00:00:00 2001 From: weitalu Date: Thu, 7 Mar 2019 15:53:35 +0800 Subject: [PATCH] docs(single): update docs for single with description and example (#4616) * docs(single) Updated docs for single with description and example --- src/internal/operators/single.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/internal/operators/single.ts b/src/internal/operators/single.ts index de7642cc25..e96dd8705c 100644 --- a/src/internal/operators/single.ts +++ b/src/internal/operators/single.ts @@ -11,8 +11,34 @@ import { Observer, MonoTypeOperatorFunction, TeardownLogic } from '../types'; * items, notify of an IllegalArgumentException or NoSuchElementException respectively. If the source Observable * emits items but none match the specified predicate then `undefined` is emitted. * + * Like {@link first}, but emit with error notification if there is more than one value. * ![](single.png) * + * ## Example + * emits 'error' + * ```javascript + * import { range } from 'rxjs'; + * import { single } from 'rxjs/operators'; + * + * const numbers = range(1,5).pipe(single()); + * numbers.subscribe(x => console.log('never get called'), e => console.log('error')); + * // result + * // 'error' + * ``` + * + * emits 'undefined' + * ```javascript + * import { range } from 'rxjs'; + * import { single } from 'rxjs/operators'; + * + * const numbers = range(1,5).pipe(single(x => x === 10)); + * numbers.subscribe(x => console.log(x)); + * // result + * // 'undefined' + * ``` + * + * @see {@link first} + * * @throws {EmptyError} Delivers an EmptyError to the Observer's `error` * callback if the Observable completes before any `next` notification was sent. * @param {Function} predicate - A predicate function to evaluate items emitted by the source Observable.