8000 Auto-generated commit · stdlib-js/utils-async-reduce@d54bb52 · GitHub
[go: up one dir, main page]

Skip to content

Commit d54bb52

Browse files
committed
Auto-generated commit
1 parent a205606 commit d54bb52

File tree

9 files changed

+99
-52
lines changed

9 files changed

+99
-52
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,8 @@ indent_size = 2
179179
[*.gypi]
180180
indent_style = space
181181
indent_size = 2
182+
183+
# Set properties for citation files:
184+
[*.{cff,cff.txt}]
185+
indent_style = space
186+
indent_size = 2

.github/workflows/productionize.yml

Lines changed: 0 additions & 15 deletions
90
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,6 @@ jobs:
8282
id: transform-error-messages
8383
uses: stdlib-js/transform-errors-action@main
8484

85-
# Format error messages:
86-
- name: 'Replace double quotes with single quotes in rewritten format string error messages'
87-
run: |
88-
find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \;
89-
-
# Format string literal error messages:
91-
- name: 'Replace double quotes with single quotes in rewritten string literal error messages'
92-
run: |
93-
find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \;
94-
95-
# Format code:
96-
- name: 'Replace double quotes with single quotes in inserted `require` calls'
97-
run: |
98-
find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \;
99-
10085
# Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency:
10186
- name: 'Update dependencies in package.json'
10287
run: |

CITATION.cff

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cff-version: 1.2.0
2+
title: stdlib
3+
message: >-
4+
If you use this software, please cite it using the
5+
metadata from this file.
6+
7+
type: software
8+
9+
authors:
10+
- name: The Stdlib Authors
11+
url: https://github.com/stdlib-js/stdlib/graphs/contributors
12+
13+
repository-code: https://github.com/stdlib-js/stdlib
14+
url: https://stdlib.io
15+
16+
abstract: |
17+
Standard library for JavaScript and Node.js.
18+
19+
keywords:
20+
- JavaScript
21+
- Node.js
22+
- TypeScript
23+
- standard library
24+
- scientific computing
25+
- numerical computing
26+
- statistical computing
27+
28+
license: Apache-2.0 AND BSL-1.0
29+
30+
date-released: 2016

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ limitations under the License.
1818
1919
-->
2020

21+
22+
<details>
23+
<summary>
24+
About stdlib...
25+
</summary>
26+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30+
</details>
31+
2132
# reduceAsync
2233

2334
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
@@ -62,7 +73,7 @@ var reduceAsync = require( '@stdlib/utils-async-reduce' );
6273

6374
#### reduceAsync( collection, initial, \[options,] reducer, done )
6475

65-
Applies a `function` against an accumulator and each element in a `collection` and returns the accumulated result.
76+
Applies a function against an accumulator and each element in a `collection` and returns the accumulated result.
6677

6778
```javascript
6879
function reducer( acc, value, index, next ) {
@@ -122,9 +133,9 @@ reduceAsync( arr, acc, reducer, done );
122133

123134
The function accepts the following `options`:
124135

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

129140
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`.
130141

@@ -244,11 +255,11 @@ function done( error, acc ) {
244255

245256
When invoked, `reducer` is provided a maximum of five arguments:
246257

247-
- `accumulator`: accumulated value.
248-
- `value`: collection value.
249-
- `index`: collection index.
250-
- `collection`: the input `collection`.
251-
- `next`: a callback which should be called once `reducer` has finished processing a collection `value`.
258+
- **accumulator**: accumulated value.
259+
- **value**: collection value.
260+
- **index**: collection index.
261+
- **collection**: the input `collection`.
262+
- **next**: a callback which should be called once `reducer` has finished processing a collection `value`.
252263

253264
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.
254265

@@ -290,7 +301,7 @@ reduceAsync( arr, acc, reducer, done );
290301

291302
#### reduceAsync.factory( \[options,] reducer )
292303

293-
Returns a `function` which invokes a function once for each element in a `collection`.
304+
Returns a function which invokes a function once for each element in a `collection`.
294305

295306
```javascript
296307
function reducer( acc, value, index, next ) {

dist/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path="../docs/types/index.d.ts" />
2+
import reduceAsync from '../docs/types/index';
3+
export = reduceAsync;

dist/index.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/types/index.d.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@
1616
* limitations under the License.
1717
*/
1818

19-
// TypeScript Version: 2.0
19+
// TypeScript Version: 4.1
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 `reduceAsync`.
@@ -132,7 +132,6 @@ interface ReduceAsync {
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 ReduceAsync {
177176
* };
178177
* reduceAsync( 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.
@@ -187,7 +186,6 @@ interface ReduceAsync {
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 reducer - function to invoke for each element in a collection
@@ -227,7 +225,7 @@ interface ReduceAsync {
227225
* };
228226
* reduceAsync( files, acc, read, done );
229227
*/
230-
( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length
228+
<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
231229

232230
/**
233231
* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result.
@@ -237,7 +235,6 @@ interface ReduceAsync {
237235
* - 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.
238236
* - 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`).
239237
*
240-
*
241238
* @param options - function options
242239
* @param options.thisArg - execution context
243240
* @param options.limit - maximum number of pending invocations at any one time
@@ -291,7 +288,7 @@ interface ReduceAsync {
291288
* };
292289
* reduceAsync( files, acc, done );
293290
*/
294-
factory( options: Options, reducer: Reducer ): FactoryFunction;
291+
factory<T = unknown, U = unknown, V = unknown>( options: Options<T, U, V>, reducer: Reducer<T, U, V> ): FactoryFunction<T, U>;
295292

296293
/**
297294
* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result.
@@ -301,7 +298,6 @@ interface ReduceAsync {
301298
* - 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.
302299
* - 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`).
303300
*
304-
*
305301
* @param reducer - function to invoke for each element in a collection
306302
* @throws must provide valid options
307303
* @returns function which invokes the provided function once for each element in a collection
@@ -347,7 +343,7 @@ interface ReduceAsync {
347343
* };
348344
* reduceAsync( files, acc, done );
349345
*/
350-
factory( reducer: Reducer ): FactoryFunction;
346+
factory<T = unknown, U = unknown, V = unknown>( reducer: Reducer<T, U, V> ): FactoryFunction<T, U>; // tslint:disable-line:no-unnecessary-generics
351347
}
352348

353349
/**
@@ -358,7 +354,6 @@ interface ReduceAsync {
358354
* - 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.
359355
* - 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`).
360356
*
361-
*
362357
* @param collection - input collection
363358
* @param initial - initial value
364359
* @param options - function options

docs/types/test.ts

Lines changed: 2 additions & 2 deletions
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-
reduceAsync.factory( reducer ); // $ExpectType FactoryFunction
94-
reduceAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction
93+
reduceAsync.factory( reducer ); // $ExpectType FactoryFunction<number, any>
94+
reduceAsync.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)
0