Skip to content

Commit 3938eac

Browse files
committed
AsyncIterator.reduce types improvements
1 parent d269b5e commit 3938eac

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

packages/core-js-types/src/base/proposals/async-iterator-helpers.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,20 @@ interface AsyncIterator<T, TReturn = any, TNext = any> {
6565
*/
6666
map<U>(mapper: (value: T, index: number) => U): AsyncIteratorObject<U, undefined, unknown>;
6767

68+
/**
69+
* Reduces the elements of the iterator to a single value using the `reducer` function.
70+
* @param reducer - A function that combines two elements of the iterator
71+
* @param initialValue - The initial value to start the accumulation. Required when the accumulator type differs from the element type.
72+
* @returns A `Promise` that resolves to the reduced value
73+
*/
74+
reduce<U>(reducer: (accumulator: U, value: T, index: number) => U, initialValue: U): Promise<U>;
75+
6876
/**
6977
* Reduces the elements of the iterator to a single value using the `reducer` function.
7078
* @param reducer - A function that combines two elements of the iterator
7179
* @param initialValue - An optional initial value to start the reduction
7280
* @returns A `Promise` that resolves to the reduced value
7381
*/
74-
reduce<U>(reducer: (accumulator: U, value: T, index: number) => U, initialValue?: U): Promise<U>;
7582
reduce(reducer: (accumulator: T, value: T, index: number) => T, initialValue?: T): Promise<T>;
7683

7784
/**

packages/core-js-types/src/base/pure/proposals/async-iterator-helpers.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ declare namespace CoreJS {
7373
/**
7474
* Reduces the elements of the iterator to a single value using the `reducer` function.
7575
* @param reducer - A function that combines two elements of the iterator
76+
* @param initialValue - The initial value to start the accumulation. Required when the accumulator type differs from the element type.
77+
* @returns A `Promise` that resolves to the reduced value
78+
*/
79+
80+
reduce<U>(reducer: (accumulator: U, value: T, index: number) => U, initialValue: U): CoreJSPromise<U>;
81+
/**
82+
* Reduces the elements of the iterator to a single value using the `reducer` function.
83+
* @param reducer - A function that combines two elements of the iterator
84+
* @param initialValue - An optional initial value to start the reduction
85+
* @returns A `Promise` that resolves to the reduced value
86+
*/
87+
reduce(reducer: (accumulator: T, value: T, index: number) => T, initialValue?: T): CoreJSPromise<T>;
88+
89+
/**
90+
* Reduces the elements of the iterator to a single value using the `reducer` function.
91+
* For maximum flexibility with any types.
92+
* @param reducer - A function that combines two elements of the iterator
7693
* @param initialValue - An optional initial value to start the reduction
7794
* @returns A `Promise` that resolves to the reduced value
7895
*/

packages/core-js-types/src/ts5-2/proposals/async-iterator-helpers.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ interface AsyncIterator<T, TReturn = any, TNext = undefined> {
6666
/**
6767
* Reduces the elements of the iterator to a single value using the `reducer` function.
6868
* @param reducer - A function that combines two elements of the iterator
69+
* @param initialValue - The initial value to start the accumulation. Required when the accumulator type differs from the element type.
70+
* @returns A `Promise` that resolves to the reduced value
71+
*/
72+
reduce<U>(reducer: (accumulator: U, value: T, index: number) => U, initialValue: U): Promise<U>;
73+
74+
/**
75+
* Reduces the elements of the iterator to a single value using the `reducer` function.
76+
* @param reducer - A function that combines two elements of the iterator
77+
* @param initialValue - An optional initial value to start the reduction
78+
* @returns A `Promise` that resolves to the reduced value
79+
*/
80+
reduce(reducer: (accumulator: T, value: T, index: number) => T, initialValue?: T): Promise<T>;
81+
82+
/**
83+
* Reduces the elements of the iterator to a single value using the `reducer` function.
84+
* For maximum flexibility with any types.
85+
* @param reducer - A function that combines two elements of the iterator
6986
* @param initialValue - An optional initial value to start the reduction
7087
* @returns A `Promise` that resolves to the reduced value
7188
*/

packages/core-js-types/src/ts5-2/pure/proposals/async-iterator-helpers.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ declare namespace CoreJS {
7272
/**
7373
* Reduces the elements of the iterator to a single value using the `reducer` function.
7474
* @param reducer - A function that combines two elements of the iterator
75+
* @param initialValue - The initial value to start the accumulation. Required when the accumulator type differs from the element type.
76+
* @returns A `Promise` that resolves to the reduced value
77+
*/
78+
reduce<U>(reducer: (accumulator: U, value: T, index: number) => U, initialValue: U): CoreJSPromise<U>;
79+
80+
/**
81+
* Reduces the elements of the iterator to a single value using the `reducer` function.
82+
* @param reducer - A function that combines two elements of the iterator
83+
* @param initialValue - An optional initial value to start the reduction
84+
* @returns A `Promise` that resolves to the reduced value
85+
*/
86+
reduce(reducer: (accumulator: T, value: T, index: number) => T, initialValue?: T): CoreJSPromise<T>;
87+
88+
/**
89+
* Reduces the elements of the iterator to a single value using the `reducer` function.
90+
* For maximum flexibility with any types.
91+
* @param reducer - A function that combines two elements of the iterator
7592
* @param initialValue - An optional initial value to start the reduction
7693
* @returns A `Promise` that resolves to the reduced value
7794
*/

0 commit comments

Comments
 (0)