| 1 | import { MemoListIterator } from '../_internal/MemoListIterator.js';
|
|---|
| 2 | import { MemoObjectIterator } from '../_internal/MemoObjectIterator.js';
|
|---|
| 3 |
|
|---|
| 4 | /**
|
|---|
| 5 | * Reduces an array to a single value using an iteratee function.
|
|---|
| 6 | *
|
|---|
| 7 | * @param {T[] | null | undefined} collection - The array to iterate over
|
|---|
| 8 | * @param {MemoListIterator<T, U, T[]>} callback - The function invoked per iteration
|
|---|
| 9 | * @param {U} accumulator - The initial value
|
|---|
| 10 | * @returns {U} Returns the accumulated value
|
|---|
| 11 | *
|
|---|
| 12 | * @example
|
|---|
| 13 | * const array = [1, 2, 3];
|
|---|
| 14 | * reduce(array, (acc, value) => acc + value, 0); // => 6
|
|---|
| 15 | */
|
|---|
| 16 | declare function reduce<T, U>(collection: T[] | null | undefined, callback: MemoListIterator<T, U, T[]>, accumulator: U): U;
|
|---|
| 17 | /**
|
|---|
| 18 | * Reduces an array-like object to a single value using an iteratee function.
|
|---|
| 19 | *
|
|---|
| 20 | * @param {ArrayLike<T> | null | undefined} collection - The array-like object to iterate over
|
|---|
| 21 | * @param {MemoListIterator<T, U, ArrayLike<T>>} callback - The function invoked per iteration
|
|---|
| 22 | * @param {U} accumulator - The initial value
|
|---|
| 23 | * @returns {U} Returns the accumulated value
|
|---|
| 24 | *
|
|---|
| 25 | * @example
|
|---|
| 26 | * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
|
|---|
| 27 | * reduce(arrayLike, (acc, value) => acc + value, 0); // => 6
|
|---|
| 28 | */
|
|---|
| 29 | declare function reduce<T, U>(collection: ArrayLike<T> | null | undefined, callback: MemoListIterator<T, U, ArrayLike<T>>, accumulator: U): U;
|
|---|
| 30 | /**
|
|---|
| 31 | * Reduces an object to a single value using an iteratee function.
|
|---|
| 32 | *
|
|---|
| 33 | * @param {T | null | undefined} collection - The object to iterate over
|
|---|
| 34 | * @param {MemoObjectIterator<T[keyof T], U, T>} callback - The function invoked per iteration
|
|---|
| 35 | * @param {U} accumulator - The initial value
|
|---|
| 36 | * @returns {U} Returns the accumulated value
|
|---|
| 37 | *
|
|---|
| 38 | * @example
|
|---|
| 39 | * const obj = { a: 1, b: 2, c: 3 };
|
|---|
| 40 | * reduce(obj, (acc, value) => acc + value, 0); // => 6
|
|---|
| 41 | */
|
|---|
| 42 | declare function reduce<T extends object, U>(collection: T | null | undefined, callback: MemoObjectIterator<T[keyof T], U, T>, accumulator: U): U;
|
|---|
| 43 | /**
|
|---|
| 44 | * Reduces an array to a single value using an iteratee function.
|
|---|
| 45 | *
|
|---|
| 46 | * @param {T[] | null | undefined} collection - The array to iterate over
|
|---|
| 47 | * @param {MemoListIterator<T, T, T[]>} callback - The function invoked per iteration
|
|---|
| 48 | * @returns {T | undefined} Returns the accumulated value
|
|---|
| 49 | *
|
|---|
| 50 | * @example
|
|---|
| 51 | * const array = [1, 2, 3];
|
|---|
| 52 | * reduce(array, (acc, value) => acc + value); // => 6
|
|---|
| 53 | */
|
|---|
| 54 | declare function reduce<T>(collection: T[] | null | undefined, callback: MemoListIterator<T, T, T[]>): T | undefined;
|
|---|
| 55 | /**
|
|---|
| 56 | * Reduces an array-like object to a single value using an iteratee function.
|
|---|
| 57 | *
|
|---|
| 58 | * @param {ArrayLike<T> | null | undefined} collection - The array-like object to iterate over
|
|---|
| 59 | * @param {MemoListIterator<T, T, ArrayLike<T>>} callback - The function invoked per iteration
|
|---|
| 60 | * @returns {T | undefined} Returns the accumulated value
|
|---|
| 61 | *
|
|---|
| 62 | * @example
|
|---|
| 63 | * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
|
|---|
| 64 | * reduce(arrayLike, (acc, value) => acc + value); // => 6
|
|---|
| 65 | */
|
|---|
| 66 | declare function reduce<T>(collection: ArrayLike<T> | null | undefined, callback: MemoListIterator<T, T, ArrayLike<T>>): T | undefined;
|
|---|
| 67 | /**
|
|---|
| 68 | * Reduces an object to a single value using an iteratee function.
|
|---|
| 69 | *
|
|---|
| 70 | * @param {T | null | undefined} collection - The object to iterate over
|
|---|
| 71 | * @param {MemoObjectIterator<T[keyof T], T[keyof T], T>} callback - The function invoked per iteration
|
|---|
| 72 | * @returns {T[keyof T] | undefined} Returns the accumulated value
|
|---|
| 73 | *
|
|---|
| 74 | * @example
|
|---|
| 75 | * const obj = { a: 1, b: 2, c: 3 };
|
|---|
| 76 | * reduce(obj, (acc, value) => acc + value); // => 6
|
|---|
| 77 | */
|
|---|
| 78 | declare function reduce<T extends object>(collection: T | null | undefined, callback: MemoObjectIterator<T[keyof T], T[keyof T], T>): T[keyof T] | undefined;
|
|---|
| 79 |
|
|---|
| 80 | export { reduce };
|
|---|