1 | import { IterableOrArrayLike } from './iter';
|
2 | /**
|
3 | * Summarize all values in an iterable using a reducer function.
|
4 | *
|
5 | * @param object - The iterable or array-like object of interest.
|
6 | *
|
7 | * @param fn - The reducer function to invoke for each value.
|
8 | *
|
9 | * @param initial - The initial value to start accumulation.
|
10 | *
|
11 | * @returns The final accumulated value.
|
12 | *
|
13 | * #### Notes
|
14 | * The `reduce` function follows the conventions of `Array#reduce`.
|
15 | *
|
16 | * If the iterator is empty, an initial value is required. That value
|
17 | * will be used as the return value. If no initial value is provided,
|
18 | * an error will be thrown.
|
19 | *
|
20 | * If the iterator contains a single item and no initial value is
|
21 | * provided, the single item is used as the return value.
|
22 | *
|
23 | * Otherwise, the reducer is invoked for each element in the iterable.
|
24 | * If an initial value is not provided, the first element will be used
|
25 | * as the initial accumulated value.
|
26 | *
|
27 | * #### Complexity
|
28 | * Linear.
|
29 | *
|
30 | * #### Example
|
31 | * ```typescript
|
32 | * import { reduce } from '@lumino/algorithm';
|
33 | *
|
34 | * let data = [1, 2, 3, 4, 5];
|
35 | *
|
36 | * let sum = reduce(data, (a, value) => a + value); // 15
|
37 | * ```
|
38 | */
|
39 | export declare function reduce<T>(object: IterableOrArrayLike<T>, fn: (accumulator: T, value: T, index: number) => T): T;
|
40 | export declare function reduce<T, U>(object: IterableOrArrayLike<T>, fn: (accumulator: U, value: T, index: number) => U, initial: U): U;
|
41 | //# sourceMappingURL=reduce.d.ts.map |
\ | No newline at end of file |