1 import { reduce } from './reduce';
2 import { OperatorFunction } from '../types';
4 function toArrayReducer<T>(arr: T[], item: T, index: number) {
13 * Collects all source emissions and emits them as an array when the source completes.
15 * <span class="informal">Get all values inside an array when the source completes</span>
19 * `toArray` will wait until the source Observable completes before emitting
20 * the array containing all emissions. When the source Observable errors no
21 * array will be emitted.
25 * import { interval } from 'rxjs';
26 * import { toArray, take } from 'rxjs/operators';
28 * const source = interval(1000);
29 * const example = source.pipe(
34 * const subscribe = example.subscribe(val => console.log(val));
36 * // output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
39 * @return An array from an observable sequence.
43 export function toArray<T>(): OperatorFunction<T, T[]> {
44 return reduce(toArrayReducer, [] as T[]);