| [a762898] | 1 | import { MemoListIterator } from '../_internal/MemoListIterator.mjs';
|
|---|
| 2 | import { MemoObjectIterator } from '../_internal/MemoObjectIterator.mjs';
|
|---|
| 3 |
|
|---|
| 4 | /**
|
|---|
| 5 | * Reduces an array to a single value using an iteratee function, starting from the right.
|
|---|
| 6 | *
|
|---|
| 7 | * The `reduceRight()` function goes through each element in an array from right to left and applies a special function (called a "reducer") to them, one by one.
|
|---|
| 8 | * This function takes the result of the previous step and the current element to perform a calculation.
|
|---|
| 9 | * After going through all the elements, the function gives you one final result.
|
|---|
| 10 | *
|
|---|
| 11 | * When the `reduceRight()` function starts, there's no previous result to use.
|
|---|
| 12 | * If you provide an initial value, it starts with that.
|
|---|
| 13 | * If not, it uses the last element of the array and begins with the second to last element for the calculation.
|
|---|
| 14 | *
|
|---|
| 15 | * The `reduceRight()` function goes through each element in an array from right to left and applies a special function (called a "reducer") to them, one by one.
|
|---|
| 16 | * This function takes the result of the previous step and the current element to perform a calculation.
|
|---|
| 17 | * After going through all the elements, the function gives you one final result.
|
|---|
| 18 | *
|
|---|
| 19 | * When the `reduceRight()` function starts, there's no previous result to use.
|
|---|
| 20 | * If you provide an initial value, it starts with that.
|
|---|
| 21 | * If not, it uses the last element of the array and begins with the second to last element for the calculation.
|
|---|
| 22 | *
|
|---|
| 23 | * @template T, U
|
|---|
| 24 | * @param {T[] | null | undefined} collection - The array to iterate over.
|
|---|
| 25 | * @param {MemoListIterator<T, U, T[]>} callback - The function invoked per iteration.
|
|---|
| 26 | * @param {U} accumulator - The initial value.
|
|---|
| 27 | * @returns {U} Returns the accumulated value.
|
|---|
| 28 | *
|
|---|
| 29 | * @example
|
|---|
| 30 | * reduceRight([1, 2, 3], (acc, value) => acc + value, 0);
|
|---|
| 31 | * // => 6
|
|---|
| 32 | */
|
|---|
| 33 | declare function reduceRight<T, U>(collection: T[] | null | undefined, callback: MemoListIterator<T, U, T[]>, accumulator: U): U;
|
|---|
| 34 | /**
|
|---|
| 35 | * Reduces an array-like collection to a single value using an iteratee function, starting from the right.
|
|---|
| 36 | *
|
|---|
| 37 | * @template T, U
|
|---|
| 38 | * @param {ArrayLike<T> | null | undefined} collection - The array-like collection to iterate over.
|
|---|
| 39 | * @param {MemoListIterator<T, U, ArrayLike<T>>} callback - The function invoked per iteration.
|
|---|
| 40 | * @param {U} accumulator - The initial value.
|
|---|
| 41 | * @returns {U} Returns the accumulated value.
|
|---|
| 42 | *
|
|---|
| 43 | * @example
|
|---|
| 44 | * reduceRight([1, 2, 3], (acc, value) => acc + value, 0);
|
|---|
| 45 | * // => 6
|
|---|
| 46 | */
|
|---|
| 47 | declare function reduceRight<T, U>(collection: ArrayLike<T> | null | undefined, callback: MemoListIterator<T, U, ArrayLike<T>>, accumulator: U): U;
|
|---|
| 48 | /**
|
|---|
| 49 | * Reduces an object to a single value using an iteratee function, starting from the right.
|
|---|
| 50 | *
|
|---|
| 51 | * @template T, U
|
|---|
| 52 | * @param {T | null | undefined} collection - The object to iterate over.
|
|---|
| 53 | * @param {MemoObjectIterator<T[keyof T], U, T>} callback - The function invoked per iteration.
|
|---|
| 54 | * @param {U} accumulator - The initial value.
|
|---|
| 55 | * @returns {U} Returns the accumulated value.
|
|---|
| 56 | *
|
|---|
| 57 | * @example
|
|---|
| 58 | * reduceRight({ a: 1, b: 2, c: 3 }, (acc, value) => acc + value, 0);
|
|---|
| 59 | * // => 6
|
|---|
| 60 | */
|
|---|
| 61 | declare function reduceRight<T extends object, U>(collection: T | null | undefined, callback: MemoObjectIterator<T[keyof T], U, T>, accumulator: U): U;
|
|---|
| 62 | /**
|
|---|
| 63 | * Reduces an array to a single value using an iteratee function, starting from the right.
|
|---|
| 64 | *
|
|---|
| 65 | * The `reduceRight()` function goes through each element in an array from right to left and applies a special function (called a "reducer") to them, one by one.
|
|---|
| 66 | * This function takes the result of the previous step and the current element to perform a calculation.
|
|---|
| 67 | * After going through all the elements, the function gives you one final result.
|
|---|
| 68 | *
|
|---|
| 69 | * When the `reduceRight()` function starts, there's no previous result to use.
|
|---|
| 70 | * If you provide an initial value, it starts with that.
|
|---|
| 71 | * If not, it uses the last element of the array and begins with the second to last element for the calculation.
|
|---|
| 72 | *
|
|---|
| 73 | * The `reduceRight()` function goes through each element in an array from right to left and applies a special function (called a "reducer") to them, one by one.
|
|---|
| 74 | * This function takes the result of the previous step and the current element to perform a calculation.
|
|---|
| 75 | * After going through all the elements, the function gives you one final result.
|
|---|
| 76 | *
|
|---|
| 77 | * When the `reduceRight()` function starts, there's no previous result to use.
|
|---|
| 78 | * If you provide an initial value, it starts with that.
|
|---|
| 79 | * If not, it uses the last element of the array and begins with the second to last element for the calculation.
|
|---|
| 80 | *
|
|---|
| 81 | * @template T
|
|---|
| 82 | * @param {T[] | null | undefined} collection - The array to iterate over.
|
|---|
| 83 | * @param {MemoListIterator<T, T, T[]>} callback - The function invoked per iteration.
|
|---|
| 84 | * @returns {T | undefined} Returns the accumulated value.
|
|---|
| 85 | *
|
|---|
| 86 | * @example
|
|---|
| 87 | * reduceRight([1, 2, 3], (acc, value) => acc + value);
|
|---|
| 88 | * // => 6
|
|---|
| 89 | */
|
|---|
| 90 | declare function reduceRight<T>(collection: T[] | null | undefined, callback: MemoListIterator<T, T, T[]>): T | undefined;
|
|---|
| 91 | /**
|
|---|
| 92 | * Reduces an array-like collection to a single value using an iteratee function, starting from the right.
|
|---|
| 93 | *
|
|---|
| 94 | * @template T
|
|---|
| 95 | * @param {ArrayLike<T> | null | undefined} collection - The array-like collection to iterate over.
|
|---|
| 96 | * @param {MemoListIterator<T, T, ArrayLike<T>>} callback - The function invoked per iteration.
|
|---|
| 97 | * @returns {T | undefined} Returns the accumulated value.
|
|---|
| 98 | *
|
|---|
| 99 | * @example
|
|---|
| 100 | * reduceRight([1, 2, 3], (acc, value) => acc + value);
|
|---|
| 101 | * // => 6
|
|---|
| 102 | */
|
|---|
| 103 | declare function reduceRight<T>(collection: ArrayLike<T> | null | undefined, callback: MemoListIterator<T, T, ArrayLike<T>>): T | undefined;
|
|---|
| 104 | /**
|
|---|
| 105 | * Reduces an object to a single value using an iteratee function, starting from the right.
|
|---|
| 106 | *
|
|---|
| 107 | * @template T
|
|---|
| 108 | * @param {T | null | undefined} collection - The object to iterate over.
|
|---|
| 109 | * @param {MemoObjectIterator<T[keyof T], T[keyof T], T>} callback - The function invoked per iteration.
|
|---|
| 110 | * @returns {T[keyof T] | undefined} Returns the accumulated value.
|
|---|
| 111 | *
|
|---|
| 112 | * @example
|
|---|
| 113 | * reduceRight({ a: 1, b: 2, c: 3 }, (acc, value) => acc + value);
|
|---|
| 114 | * // => 6
|
|---|
| 115 | */
|
|---|
| 116 | declare function reduceRight<T extends object>(collection: T | null | undefined, callback: MemoObjectIterator<T[keyof T], T[keyof T], T>): T[keyof T] | undefined;
|
|---|
| 117 |
|
|---|
| 118 | export { reduceRight };
|
|---|