From 68d51286feaa6acf78046a183a59097725ca3467 Mon Sep 17 00:00:00 2001 From: Waseem Ahmad <42496021+waseemahmad31@users.noreply.github.com> Date: Wed, 5 Jun 2019 21:59:31 +0530 Subject: [PATCH] docs(toArray): added description and example for toArray (#4775) --- src/internal/operators/toArray.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/internal/operators/toArray.ts b/src/internal/operators/toArray.ts index c1f1896398..40d05601c3 100644 --- a/src/internal/operators/toArray.ts +++ b/src/internal/operators/toArray.ts @@ -9,6 +9,37 @@ function toArrayReducer(arr: T[], item: T, index: number) { return arr; } +/** + * Collects all source emissions and emits them as an array when the source completes. + * + * Get all values inside an array when the source completes + * + * ![](toArray.png) + * + * `toArray` will wait until the source Observable completes before emitting + * the array containing all emissions. When the source Observable errors no + * array will be emitted. + * + * ## Example + * ```ts + * import { interval } from 'rxjs'; + * import { toArray, take } from 'rxjs/operators'; + * + * const source = interval(1000); + * const example = source.pipe( + * take(10), + * toArray() + * ); + * + * const subscribe = example.subscribe(val => console.log(val)); + * + * // output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + * + * ``` +* @return An array from an observable sequence. +* @method toArray +* @owner Observable +*/ export function toArray(): OperatorFunction { return reduce(toArrayReducer, [] as T[]); }