Skip to content

Commit 4dc4968

Browse files
committed
fix: update import path for Collection type definition and refactor to use generics
Ref: bde4671
1 parent 5c93dea commit 4dc4968

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

lib/node_modules/@stdlib/utils/async/reduce-right/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var reduceRightAsync = require( '@stdlib/utils/async/reduce-right' );
4242

4343
#### reduceRightAsync( collection, initial, \[options,] reducer, done )
4444

45-
Applies a `function` against an accumulator and each element in a `collection` and returns the accumulated result, iterating from right to left.
45+
Applies a function against an accumulator and each element in a `collection` and returns the accumulated result, iterating from right to left.
4646

4747
```javascript
4848
function reducer( acc, value, index, next ) {
@@ -102,9 +102,9 @@ reduceRightAsync( arr, acc, reducer, done );
102102

103103
The function accepts the following `options`:
104104

105-
- `limit`: the maximum number of pending invocations at any one time. If provided, the function sets `options.series=false`. Default: `infinity`.
106-
- `series`: `boolean` indicating whether to sequentially invoke `reducer` for each `collection` element. If `true`, the function sets `options.limit=1`. Default: `true`.
107-
- `thisArg`: the execution context for `reducer`.
105+
- **limit**: the maximum number of pending invocations at any one time. If provided, the function sets `options.series=false`. Default: `infinity`.
106+
- **series**: boolean indicating whether to sequentially invoke `reducer` for each `collection` element. If `true`, the function sets `options.limit=1`. Default: `true`.
107+
- **thisArg**: the execution context for `reducer`.
108108

109109
By default, all elements are processed **sequentially**, which means that the function **does** guarantee completion order. To process each `collection` element concurrently, set the `series` option to `false`.
110110

@@ -224,11 +224,11 @@ function done( error, acc ) {
224224

225225
When invoked, `reducer` is provided a maximum of five arguments:
226226

227-
- `accumulator`: accumulated value.
228-
- `value`: collection value.
229-
- `index`: collection index.
230-
- `collection`: the input `collection`.
231-
- `next`: a callback which should be called once `reducer` has finished processing a collection `value`.
227+
- **accumulator**: accumulated value.
228+
- **value**: collection value.
229+
- **index**: collection index.
230+
- **collection**: the input `collection`.
231+
- **next**: a callback which should be called once `reducer` has finished processing a collection `value`.
232232

233233
The actual number of provided arguments depends on function `length`. If `reducer` accepts three arguments, `reducer` is provided `accumulator`, `value` and `next`. If `reducer` accepts four arguments, `reducer` is provided `accumulator`, `value`, `index`, and `next`. For every other `reducer` signature, `reducer` is provided all five arguments.
234234

@@ -270,7 +270,7 @@ reduceRightAsync( arr, acc, reducer, done );
270270

271271
#### reduceRightAsync.factory( \[options,] reducer )
272272

273-
Returns a `function` which invokes a function once for each element in a `collection`, iterating from right to left.
273+
Returns a function which invokes a function once for each element in a `collection`, iterating from right to left.
274274

275275
```javascript
276276
function reducer( acc, value, index, next ) {

lib/node_modules/@stdlib/utils/async/reduce-right/docs/types/index.d.ts

+19-24
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { Collection } from '@stdlib/types/object';
23+
import { Collection } from '@stdlib/types/array';
2424

2525
/**
2626
* Interface defining function options.
2727
*/
28-
interface Options {
28+
interface Options<T, U, V> {
2929
/**
30-
* The maximum number of pending invocations at any one time.
30+
* Execution context.
3131
*/
32-
limit?: number;
32+
thisArg?: ThisParameterType<Reducer<T, U, V>>;
3333

3434
/**
35-
* Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true).
35+
* The maximum number of pending invocations at any one time.
3636
*/
37-
series?: boolean;
37+
limit?: number;
3838

3939
/**
40-
* Execution context.
40+
* Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true.
4141
*/
42-
thisArg?: any;
42+
series?: boolean;
4343
}
4444

4545
/**
@@ -60,15 +60,15 @@ type Unary = ( error: Error | null ) => void;
6060
* @param error - encountered error or null
6161
* @param accumulator - accumulated value
6262
*/
63-
type Binary = ( error: Error | null, accumulator: any ) => void;
63+
type Binary<U> = ( error: Error | null, accumulator: U ) => void;
6464

6565
/**
6666
* Callback function.
6767
*
6868
* @param error - encountered error or null
6969
* @param accumulator - accumulated value
7070
*/
71-
type Callback = Nullary | Unary | Binary;
71+
type Callback<U> = Nullary | Unary | Binary<U>;
7272

7373
/**
7474
* Reducer function invoked for each element in a collection.
@@ -77,7 +77,7 @@ type Callback = Nullary | Unary | Binary;
7777
* @param value - collection value
7878
* @param next - a callback to be invoked after processing a collection `value`
7979
*/
80-
type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void;
80+
type TernaryReducer<T, U, V> = ( this: V, accumulator: U, value: T, next: Callback<U> ) => void;
8181

8282
/**
8383
* Reducer function invoked for each element in a collection.
@@ -87,7 +87,7 @@ type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void;
8787
* @param index - collection index
8888
* @param next - a callback to be invoked after processing a collection `value`
8989
*/
90-
type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length
90+
type QuaternaryReducer <T, U, V> = ( this: V, accumulator: U, value: T, index: number, next: Callback<U> ) => void;
9191

9292
/**
9393
* Reducer function invoked for each element in a collection.
@@ -98,7 +98,7 @@ type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Ca
9898
* @param collection - the input collection
9999
* @param next - a callback to be invoked after processing a collection `value`
100100
*/
101-
type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length
101+
type QuinaryReducer<T, U, V> = ( this: V, accumulator: U, value: T, index: number, collection: Collection<T>, next: Callback<U> ) => void;
102102

103103
/**
104104
* Reducer function invoked for each element in a collection.
@@ -109,7 +109,7 @@ type QuinaryReducer = ( accumulator: any, value: any, index: number, collection:
109109
* @param collection - the input collection
110110
* @param next - a callback to be invoked after processing a collection `value`
111111
*/
112-
type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer;
112+
type Reducer<T, U, V> = TernaryReducer<T, U, V> | QuaternaryReducer<T, U, V> | QuinaryReducer<T, U, V>;
113113

114114
/**
115115
* Applies a function against an accumulator and each element in a collection and return the accumulated result.
@@ -118,7 +118,7 @@ type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer;
118118
* @param initial - initial value
119119
* @param done - function to invoke upon completion
120120
*/
121-
type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length
121+
type FactoryFunction<T, U> = ( collection: Collection<T>, initial: U, done: Callback<U> ) => void;
122122

123123
/**
124124
* Interface for `reduceRightAsync`.
@@ -132,7 +132,6 @@ interface ReduceRightAsync {
132132
* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
133133
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
134134
*
135-
*
136135
* @param collection - input collection
137136
* @param initial - initial value
138137
* @param options - function options
@@ -177,7 +176,7 @@ interface ReduceRightAsync {
177176
* };
178177
* reduceRightAsync( files, acc, {}, read, done );
179178
*/
180-
( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length
179+
<T = unknown, U = unknown, V = unknown>( collection: Collection<T>, initial: U, options: Options<T, U, V>, reducer: Reducer<T, U, V>, done: Callback<U> ): void;
181180

182181
/**
183182
* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.
@@ -187,7 +186,6 @@ interface ReduceRightAsync {
187186
* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
188187
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
189188
*
190-
*
191189
* @param collection - input collection
192190
* @param initial - initial value
193191
* @param options - function options
@@ -232,7 +230,7 @@ interface ReduceRightAsync {
232230
* };
233231
* reduceRightAsync( files, acc, read, done );
234232
*/
235-
( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length
233+
<T = unknown, U = unknown, V = unknown>( collection: Collection<T>, initial: U, reducer: Reducer<T, U, V>, done: Callback<U> ): void; // tslint:disable-line:no-unnecessary-generics
236234

237235
/**
238236
* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.
@@ -242,7 +240,6 @@ interface ReduceRightAsync {
242240
* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
243241
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
244242
*
245-
*
246243
* @param options - function options
247244
* @param options.thisArg - execution context
248245
* @param options.limit - maximum number of pending invocations at any one time
@@ -296,7 +293,7 @@ interface ReduceRightAsync {
296293
* };
297294
* reduceRightAsync( files, acc, done );
298295
*/
299-
factory( options: Options, reducer: Reducer ): FactoryFunction;
296+
factory<T = unknown, U = unknown, V = unknown>( options: Options<T, U, V>, reducer: Reducer<T, U, V> ): FactoryFunction<T, U>;
300297

301298
/**
302299
* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.
@@ -306,7 +303,6 @@ interface ReduceRightAsync {
306303
* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
307304
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
308305
*
309-
*
310306
* @param reducer - function to invoke for each element in a collection
311307
* @returns function which invokes the provided function once for each element in a collection
312308
*
@@ -351,7 +347,7 @@ interface ReduceRightAsync {
351347
* };
352348
* reduceRightAsync( files, acc, done );
353349
*/
354-
factory( reducer: Reducer ): FactoryFunction;
350+
factory<T = unknown, U = unknown, V = unknown>( reducer: Reducer<T, U, V> ): FactoryFunction<T, U>; // tslint:disable-line:no-unnecessary-generics
355351
}
356352

357353
/**
@@ -362,7 +358,6 @@ interface ReduceRightAsync {
362358
* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
363359
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
364360
*
365-
*
366361
* @param collection - input collection
367362
* @param initial - initial value
368363
* @param options - function options

lib/node_modules/@stdlib/utils/async/reduce-right/docs/types/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ const done = ( error: Error | null, acc: any ) => {
9090

9191
// Attached to main export is a `factory` method which returns a function...
9292
{
93-
reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction
94-
reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction
93+
reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction<number, any>
94+
reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction<number, any>
9595
}
9696

9797
// The compiler throws an error if the `factory` method is provided an options argument which is not an object...

0 commit comments

Comments
 (0)