@stdlib/utils-reduce 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CITATION.cff ADDED
@@ -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
package/LICENSE CHANGED
@@ -175,307 +175,3 @@
175
175
  of your accepting any such warranty or additional liability.
176
176
 
177
177
  END OF TERMS AND CONDITIONS
178
-
179
-
180
-
181
- Boost Software License - Version 1.0 - August 17th, 2003
182
-
183
- Permission is hereby granted, free of charge, to any person or organization
184
- obtaining a copy of the software and accompanying documentation covered by this
185
- license (the "Software") to use, reproduce, display, distribute, execute, and
186
- transmit the Software, and to prepare derivative works of the Software, and to
187
- permit third-parties to whom the Software is furnished to do so, all subject to
188
- the following:
189
-
190
- The copyright notices in the Software and this entire statement, including the
191
- above license grant, this restriction and the following disclaimer, must be
192
- included in all copies of the Software, in whole or in part, and all derivative
193
- works of the Software, unless such copies or derivative works are solely in the
194
- form of machine-executable object code generated by a source language processor.
195
-
196
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
198
- FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
199
- COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES
200
- OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
201
- OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
202
-
203
-
204
-
205
-
206
- DEPENDENCIES
207
-
208
- The library links against the following external libraries, which have their own
209
- licenses:
210
-
211
- * OpenBLAS <https://raw.githubusercontent.com/xianyi/OpenBLAS/
212
- def146efed8d5908ea04e22668feeab7099599a0/LICENSE>
213
-
214
- Copyright (c) 2011-2014, The OpenBLAS Project
215
- All rights reserved.
216
-
217
- Redistribution and use in source and binary forms, with or without
218
- modification, are permitted provided that the following conditions are
219
- met:
220
-
221
- 1. Redistributions of source code must retain the above copyright
222
- notice, this list of conditions and the following disclaimer.
223
-
224
- 2. Redistributions in binary form must reproduce the above copyright
225
- notice, this list of conditions and the following disclaimer in
226
- the documentation and/or other materials provided with the
227
- distribution.
228
-
229
- 3. Neither the name of the OpenBLAS project nor the names of
230
- its contributors may be used to endorse or promote products
231
- derived from this software without specific prior written
232
- permission.
233
-
234
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
235
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
236
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
237
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
238
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
239
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
240
- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
243
- THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
244
-
245
-
246
- * Electron <https://raw.githubusercontent.com/electron/electron/
247
- c4cfb3e7110266b9d7ad80e1ae097c4db564501c/LICENSE>
248
-
249
- Copyright (c) 2013-2017 GitHub Inc.
250
-
251
- Permission is hereby granted, free of charge, to any person obtaining
252
- a copy of this software and associated documentation files (the
253
- "Software"), to deal in the Software without restriction, including
254
- without limitation the rights to use, copy, modify, merge, publish,
255
- distribute, sublicense, and/or sell copies of the Software, and to
256
- permit persons to whom the Software is furnished to do so, subject to
257
- the following conditions:
258
-
259
- The above copyright notice and this permission notice shall be
260
- included in all copies or substantial portions of the Software.
261
-
262
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
263
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
264
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
265
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
266
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
267
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
268
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
269
-
270
-
271
- * Boost <http://www.boost.org/LICENSE_1_0.txt>
272
-
273
- Boost Software License - Version 1.0 - August 17th, 2003
274
-
275
- Permission is hereby granted, free of charge, to any person or organization
276
- obtaining a copy of the software and accompanying documentation covered by
277
- this license (the "Software") to use, reproduce, display, distribute,
278
- execute, and transmit the Software, and to prepare derivative works of the
279
- Software, and to permit third-parties to whom the Software is furnished to
280
- do so, all subject to the following:
281
-
282
- The copyright notices in the Software and this entire statement, including
283
- the above license grant, this restriction and the following disclaimer,
284
- must be included in all copies of the Software, in whole or in part, and
285
- all derivative works of the Software, unless such copies or derivative
286
- works are solely in the form of machine-executable object code generated by
287
- a source language processor.
288
-
289
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
290
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
291
- FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
292
- SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
293
- FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
294
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
295
- DEALINGS IN THE SOFTWARE.
296
-
297
-
298
- * Cephes <http://www.netlib.org/cephes/readme>
299
-
300
- Copyright (c) 1984-2000 Stephen L. Moshier
301
-
302
- Some software in this archive may be from the book _Methods and Programs for
303
- Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989)
304
- or from the Cephes Mathematical Library, a commercial product. In either event,
305
- it is copyrighted by the author. What you see here may be used freely but it
306
- comes with no support or guarantee.
307
-
308
- Stephen L. Moshier
309
- moshier@na-net.ornl.gov
310
-
311
-
312
-
313
- ATTRIBUTION
314
-
315
- The library contains implementations from the following external libraries,
316
- which have their own licenses:
317
-
318
- * FreeBSD <https://svnweb.freebsd.org/>
319
-
320
- Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved.
321
-
322
- Developed at SunPro, a Sun Microsystems, Inc. business.
323
- Permission to use, copy, modify, and distribute this
324
- software is freely granted, provided that this notice
325
- is preserved.
326
-
327
-
328
- * FDLIBM <http://www.netlib.org/fdlibm/>
329
-
330
- Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
331
-
332
- Developed at SunPro, a Sun Microsystems, Inc. business.
333
- Permission to use, copy, modify, and distribute this
334
- software is freely granted, provided that this notice
335
- is preserved.
336
-
337
-
338
- * Go <https://raw.githubusercontent.com/golang/go/master/LICENSE>
339
-
340
- Copyright (c) 2009 The Go Authors. All rights reserved.
341
-
342
- Redistribution and use in source and binary forms, with or without
343
- modification, are permitted provided that the following conditions are
344
- met:
345
-
346
- * Redistributions of source code must retain the above copyright
347
- notice, this list of conditions and the following disclaimer.
348
- * Redistributions in binary form must reproduce the above
349
- copyright notice, this list of conditions and the following disclaimer
350
- in the documentation and/or other materials provided with the
351
- distribution.
352
- * Neither the name of Google Inc. nor the names of its
353
- contributors may be used to endorse or promote products derived from
354
- this software without specific prior written permission.
355
-
356
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
357
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
358
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
359
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
360
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
361
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
362
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
363
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
365
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
366
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367
-
368
-
369
- * SLATEC Common Mathematical Library <http://www.netlib.no/netlib/slatec/>
370
-
371
- Public domain.
372
-
373
-
374
- * ESLint <https://raw.githubusercontent.com/eslint/eslint/master/LICENSE>
375
-
376
- Copyright JS Foundation and other contributors, https://js.foundation
377
-
378
- Permission is hereby granted, free of charge, to any person obtaining a copy
379
- of this software and associated documentation files (the "Software"), to deal
380
- in the Software without restriction, including without limitation the rights
381
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
382
- copies of the Software, and to permit persons to whom the Software is
383
- furnished to do so, subject to the following conditions:
384
-
385
- The above copyright notice and this permission notice shall be included in
386
- all copies or substantial portions of the Software.
387
-
388
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
389
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
390
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
391
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
392
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
393
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
394
- THE SOFTWARE.
395
-
396
-
397
- * StatsFuns.jl <https://raw.githubusercontent.com/JuliaStats/StatsFuns.jl/
398
- e66dd973650c375bc1739c820e5b96bb5bd000a8/LICENSE.md>
399
-
400
- Copyright (c) 2015: Dahua Lin.
401
-
402
- Permission is hereby granted, free of charge, to any person obtaining
403
- a copy of this software and associated documentation files (the
404
- "Software"), to deal in the Software without restriction, including
405
- without limitation the rights to use, copy, modify, merge, publish,
406
- distribute, sublicense, and/or sell copies of the Software, and to
407
- permit persons to whom the Software is furnished to do so, subject to
408
- the following conditions:
409
-
410
- The above copyright notice and this permission notice shall be
411
- included in all copies or substantial portions of the Software.
412
-
413
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
414
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
415
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
416
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
417
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
418
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
419
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
420
-
421
-
422
- * SpecialFunctions.jl <https://raw.githubusercontent.com/JuliaMath/
423
- SpecialFunctions.jl/02a173fbe24a61c4b392aec17a9764ac5727feb1/LICENSE>
424
-
425
- The MIT License (MIT)
426
-
427
- Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others:
428
-
429
- https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors
430
-
431
- Permission is hereby granted, free of charge, to any person obtaining a copy
432
- of this software and associated documentation files (the "Software"), to deal
433
- in the Software without restriction, including without limitation the rights
434
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
435
- copies of the Software, and to permit persons to whom the Software is
436
- furnished to do so, subject to the following conditions:
437
-
438
- The above copyright notice and this permission notice shall be included in all
439
- copies or substantial portions of the Software.
440
-
441
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
442
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
443
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
444
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
445
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
446
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
447
- SOFTWARE.
448
-
449
-
450
- * MT19937 <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/
451
- mt19937ar.c>
452
-
453
- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
454
- All rights reserved.
455
-
456
- Redistribution and use in source and binary forms, with or without
457
- modification, are permitted provided that the following conditions
458
- are met:
459
-
460
- 1. Redistributions of source code must retain the above copyright
461
- notice, this list of conditions and the following disclaimer.
462
-
463
- 2. Redistributions in binary form must reproduce the above copyright
464
- notice, this list of conditions and the following disclaimer in the
465
- documentation and/or other materials provided with the distribution.
466
-
467
- 3. The names of its contributors may not be used to endorse or promote
468
- products derived from this software without specific prior written
469
- permission.
470
-
471
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
472
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
473
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
474
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
475
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
476
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
477
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
478
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
479
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
480
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
481
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2022 The Stdlib Authors.
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md CHANGED
@@ -18,6 +18,17 @@ limitations under the License.
18
18
 
19
19
  -->
20
20
 
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
+
21
32
  # reduce
22
33
 
23
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
@@ -227,9 +238,9 @@ console.log( 'sum: %d', out );
227
238
 
228
239
  ## See Also
229
240
 
230
- - <span class="package-name">[`@stdlib/utils/for-each`][@stdlib/utils/for-each]</span><span class="delimiter">: </span><span class="description">invoke a function for each element in a collection.</span>
231
- - <span class="package-name">[`@stdlib/utils/async/reduce`][@stdlib/utils/async/reduce]</span><span class="delimiter">: </span><span class="description">apply a function against an accumulator and each element in a collection and return the accumulated result.</span>
232
- - <span class="package-name">[`@stdlib/utils/reduce-right`][@stdlib/utils/reduce-right]</span><span class="delimiter">: </span><span class="description">apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.</span>
241
+ - <span class="package-name">[`@stdlib/utils-for-each`][@stdlib/utils/for-each]</span><span class="delimiter">: </span><span class="description">invoke a function for each element in a collection.</span>
242
+ - <span class="package-name">[`@stdlib/utils-async/reduce`][@stdlib/utils/async/reduce]</span><span class="delimiter">: </span><span class="description">apply a function against an accumulator and each element in a collection and return the accumulated result.</span>
243
+ - <span class="package-name">[`@stdlib/utils-reduce-right`][@stdlib/utils/reduce-right]</span><span class="delimiter">: </span><span class="description">apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.</span>
233
244
 
234
245
  </section>
235
246
 
@@ -261,7 +272,7 @@ See [LICENSE][stdlib-license].
261
272
 
262
273
  ## Copyright
263
274
 
264
- Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
275
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
265
276
 
266
277
  </section>
267
278
 
@@ -274,8 +285,8 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
274
285
  [npm-image]: http://img.shields.io/npm/v/@stdlib/utils-reduce.svg
275
286
  [npm-url]: https://npmjs.org/package/@stdlib/utils-reduce
276
287
 
277
- [test-image]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml/badge.svg
278
- [test-url]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml
288
+ [test-image]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml/badge.svg?branch=v0.1.0
289
+ [test-url]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml?query=branch:v0.1.0
279
290
 
280
291
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-reduce/main.svg
281
292
  [coverage-url]: https://codecov.io/github/stdlib-js/utils-reduce?branch=main
@@ -287,19 +298,20 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
287
298
 
288
299
  -->
289
300
 
301
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
302
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
303
+
304
+ [stdlib]: https://github.com/stdlib-js/stdlib
305
+
306
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
307
+
290
308
  [umd]: https://github.com/umdjs/umd
291
309
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
292
310
 
293
311
  [deno-url]: https://github.com/stdlib-js/utils-reduce/tree/deno
294
312
  [umd-url]: https://github.com/stdlib-js/utils-reduce/tree/umd
295
313
  [esm-url]: https://github.com/stdlib-js/utils-reduce/tree/esm
296
-
297
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
298
- [chat-url]: https://gitter.im/stdlib-js/stdlib/
299
-
300
- [stdlib]: https://github.com/stdlib-js/stdlib
301
-
302
- [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
314
+ [branches-url]: https://github.com/stdlib-js/utils-reduce/blob/main/branches.md
303
315
 
304
316
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-reduce/main/LICENSE
305
317
 
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import reduce from '../docs/types/index';
3
+ export = reduce;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";var d=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=d(function(H,b){
2
+ var j=require('@stdlib/ndarray-base-vind2bind/dist'),F="throw";function x(r,e,a,u){var i,s,t,n,o,c,f,q,l,y,v;if(n=r.length,f=r.shape,i=r.data,q=r.strides,l=r.offset,s=r.order,o=r.accessors[0],c=r.ref,f.length===0)return a.call(u,e,o(i,l),0,c);for(t=e,v=0;v<n;v++)y=j(f,q,l,s,v,F),t=a.call(u,t,o(i,y),v,c);return t}b.exports=x
3
+ });var h=d(function(I,g){
4
+ function E(r,e,a,u){var i,s,t,n;for(i=r.data,s=r.accessors[0],t=e,n=0;n<i.length;n++)t=a.call(u,t,s(i,n),n,i);return t}g.exports=E
5
+ });var w=d(function(J,k){
6
+ var T=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),O=require('@stdlib/assert-is-function/dist'),V=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist'),M=m(),z=h();function B(r,e,a,u){if(!O(a))throw new TypeError(p('1XH3N',a));if(L(r))return M(V(r),e,a,u);if(T(r))return z(D(r),e,a,u);throw new TypeError(p('1XHBH',r))}k.exports=B
7
+ });var C=w();module.exports=C;
8
+ /** @license Apache-2.0 */
9
+ /** @license Apache-2.0 */
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in an array and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array<Function>} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = reduce( x, new Complex64( 0.0, 0.0 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 16.0\n*\n* var im = imagf( v );\n* // returns 20.0\n*/\nfunction reduce( x, initial, fcn, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn fcn.call( thisArg, initial, get( xbuf, ox ), 0, ref );\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = fcn.call( thisArg, acc, get( xbuf, ix ), i, ref );\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in an array and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array<Function>} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum:\n* var out = reduce( x, 0, sum );\n* // returns 10\n*/\nfunction reduce( x, initial, fcn, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = 0; i < xbuf.length; i++ ) {\n\t\tacc = fcn.call( thisArg, acc, get( xbuf, i ), i, xbuf );\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in an array and returns the accumulated result.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} reducer - reduction function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = reduce( arr, 0, sum );\n* // returns 10\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );\n*\n* var out = reduce( arr, 0, naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction reduce( arr, initial, reducer, thisArg ) {\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, reducer, thisArg );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Apply a function against an accumulator and each element in an array and return the accumulated result.\n*\n* @module @stdlib/utils-reduce\n*\n* @example\n* var reduce = require( '@stdlib/utils-reduce' );\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = reduce( arr, 0, sum );\n* // returns 10\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var array = require( '@stdlib/ndarray-array' );\n* var reduce = require( '@stdlib/utils-reduce' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );\n*\n* var out = reduce( arr, 0, naryFunction( add, 2 ) );\n* // returns 21\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QAwEX,SAASC,EAAQC,EAAGC,EAASC,EAAKC,EAAU,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMP,EAAE,OAGRU,EAAMV,EAAE,MAGRI,EAAOJ,EAAE,KAGTW,EAAKX,EAAE,QAGPY,EAAKZ,EAAE,OAGPK,EAAOL,EAAE,MAGTQ,EAAMR,EAAE,UAAW,CAAE,EAGrBS,EAAMT,EAAE,IAGHU,EAAI,SAAW,EACnB,OAAOR,EAAI,KAAMC,EAASF,EAASO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAI5D,IADAH,EAAML,EACAa,EAAI,EAAGA,EAAIP,EAAKO,IACrBD,EAAKhB,EAAWa,EAAKC,EAAIC,EAAIP,EAAMS,EAAGhB,CAAK,EAC3CQ,EAAMJ,EAAI,KAAMC,EAASG,EAAKE,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAEvD,OAAOH,CACR,CAKAV,EAAO,QAAUG,ICxJjB,IAAAgB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsDA,SAASC,EAAQC,EAAGC,EAASC,EAAKC,EAAU,CAC3C,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOJ,EAAE,KAGTK,EAAML,EAAE,UAAW,CAAE,EAGrBM,EAAML,EACAM,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7BD,EAAMJ,EAAI,KAAMC,EAASG,EAAKD,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAEvD,OAAOE,CACR,CAKAR,EAAO,QAAUC,IC7EjB,IAAAS,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IAgDf,SAASC,EAAQC,EAAKC,EAASC,EAASC,EAAU,CACjD,GAAK,CAACV,EAAYS,CAAQ,EACzB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAQ,CAAE,EAE7G,GAAKV,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAASC,CAAQ,EAEzE,GAAKZ,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAASC,CAAQ,EAErE,MAAM,IAAI,UAAWP,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,ICvCjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "reduce", "x", "initial", "fcn", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "reduce", "x", "initial", "fcn", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "reduce", "arr", "initial", "reducer", "thisArg", "main"]
7
+ }
@@ -16,19 +16,19 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- // TypeScript Version: 2.0
19
+ // TypeScript Version: 4.1
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { Collection } from '@stdlib/types/object';
24
- import { ndarray } from '@stdlib/types/ndarray';
23
+ import { Collection } from '@stdlib/types/array';
24
+ import { typedndarray } from '@stdlib/types/ndarray';
25
25
 
26
26
  /**
27
27
  * Function applied against an accumulator.
28
28
  *
29
29
  * @returns accumulator value
30
30
  */
31
- type Nullary = () => void;
31
+ type Nullary<U, V> = ( this: V ) => U;
32
32
 
33
33
  /**
34
34
  * Function applied against an accumulator.
@@ -36,7 +36,7 @@ type Nullary = () => void;
36
36
  * @param accumulator - accumulated value
37
37
  * @returns accumulator value
38
38
  */
39
- type Unary = ( accumulator: any ) => any;
39
+ type Unary<U, V> = ( this: V, accumulator: U ) => U;
40
40
 
41
41
  /**
42
42
  * Function applied against an accumulator.
@@ -45,7 +45,7 @@ type Unary = ( accumulator: any ) => any;
45
45
  * @param value - array element
46
46
  * @returns accumulator value
47
47
  */
48
- type Binary = ( accumulator: any, value: any ) => any;
48
+ type Binary<T, U, V> = ( this: V, accumulator: U, value: T ) => U;
49
49
 
50
50
  /**
51
51
  * Function applied against an accumulator.
@@ -55,7 +55,7 @@ type Binary = ( accumulator: any, value: any ) => any;
55
55
  * @param index - element index
56
56
  * @returns accumulator value
57
57
  */
58
- type Ternary = ( accumulator: any, value: any, index: number ) => any;
58
+ type Ternary<T, U, V> = ( this: V, accumulator: U, value: T, index: number ) => U;
59
59
 
60
60
  /**
61
61
  * Function applied against an accumulator.
@@ -66,7 +66,7 @@ type Ternary = ( accumulator: any, value: any, index: number ) => any;
66
66
  * @param arr - array
67
67
  * @returns accumulator value
68
68
  */
69
- type Quaternary = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint-disable-line max-line-length
69
+ type Quaternary<T, U, V> = ( this: V, accumulator: U, value: T, index: number, arr: typedndarray<T> ) => U;
70
70
 
71
71
  /**
72
72
  * Function applied against an accumulator.
@@ -77,7 +77,7 @@ type Quaternary = ( accumulator: any, value: any, index: number, arr: ndarray )
77
77
  * @param arr - array
78
78
  * @returns accumulator value
79
79
  */
80
- type ArrayQuaternary = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint-disable-line max-line-length
80
+ type ArrayQuaternary<T, U, V> = ( this: V, accumulator: U, value: T, index: number, arr: Collection<T> ) => U;
81
81
 
82
82
  /**
83
83
  * Function applied against an accumulator.
@@ -88,7 +88,7 @@ type ArrayQuaternary = ( accumulator: any, value: any, index: number, arr: Colle
88
88
  * @param arr - array
89
89
  * @returns accumulator value
90
90
  */
91
- type Reducer = Nullary | Unary | Binary | Ternary | Quaternary;
91
+ type Reducer<T, U, V> = Nullary<U, V> | Unary<U, V> | Binary<T, U, V> | Ternary<T, U, V> | Quaternary<T, U, V>;
92
92
 
93
93
  /**
94
94
  * Function applied against an accumulator.
@@ -99,7 +99,7 @@ type Reducer = Nullary | Unary | Binary | Ternary | Quaternary;
99
99
  * @param arr - array
100
100
  * @returns accumulator value
101
101
  */
102
- type ArrayReducer = Nullary | Unary | Binary | Ternary | ArrayQuaternary;
102
+ type ArrayReducer<T, U, V> = Nullary<U, V> | Unary<U, V> | Binary<T, U, V> | Ternary<T, U, V> | ArrayQuaternary<T, U, V>;
103
103
 
104
104
  /**
105
105
  * Applies a function against an accumulator and each element in an array and returns the accumulated result.
@@ -134,7 +134,7 @@ type ArrayReducer = Nullary | Unary | Binary | Ternary | ArrayQuaternary;
134
134
  * var out = reduce( arr, 0, naryFunction( add, 2 ) );
135
135
  * // returns 21
136
136
  */
137
- declare function reduce( arr: ndarray, initial: any, reducer: Reducer, thisArg?: any ): any; // tslint-disable-line max-line-length
137
+ declare function reduce<T = unknown, U = unknown, V = unknown>( arr: typedndarray<T>, initial: U, reducer: Reducer<T, U, V>, thisArg?: ThisParameterType<Reducer<T, U, V>> ): U;
138
138
 
139
139
  /**
140
140
  * Applies a function against an accumulator and each element in an array and returns the accumulated result.
@@ -166,7 +166,7 @@ declare function reduce( arr: ndarray, initial: any, reducer: Reducer, thisArg?:
166
166
  * var out = reduce( arr, 0, sum );
167
167
  * // returns 10
168
168
  */
169
- declare function reduce( arr: Collection, initial: any, reducer: ArrayReducer, thisArg?: any ): any; // tslint-disable-line max-line-length
169
+ declare function reduce<T = unknown, U = unknown, V = unknown>( arr: Collection<T>, initial: U, reducer: ArrayReducer<T, U, V>, thisArg?: ThisParameterType<ArrayReducer<T, U, V>> ): U;
170
170
 
171
171
 
172
172
  // EXPORTS //
package/lib/array.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * @private
27
27
  * @param {Object} x - object containing input array data
28
28
  * @param {ArrayLikeObject} x.data - input array data
29
- * @param {Function} x.getter - callback for accessing input array data elements
29
+ * @param {Array<Function>} x.accessors - input array accessors
30
30
  * @param {*} initial - initial value
31
31
  * @param {Function} fcn - function to apply
32
32
  * @param {*} thisArg - function execution context
@@ -45,7 +45,7 @@
45
45
  * // Create the input array object:
46
46
  * var x = {
47
47
  * 'data': [ 1, 2, 3, 4 ],
48
- * 'getter': getter
48
+ * 'accessors': [ getter ]
49
49
  * };
50
50
  *
51
51
  * // Compute the sum:
@@ -62,7 +62,7 @@ function reduce( x, initial, fcn, thisArg ) {
62
62
  xbuf = x.data;
63
63
 
64
64
  // Cache the element accessor:
65
- get = x.getter;
65
+ get = x.accessors[ 0 ];
66
66
 
67
67
  // Iterate over each element...
68
68
  acc = initial;
package/lib/main.js CHANGED
@@ -25,6 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
25
25
  var isFunction = require( '@stdlib/assert-is-function' );
26
26
  var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );
27
27
  var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
28
+ var format = require( '@stdlib/string-format' );
28
29
  var ndarrayFcn = require( './ndarray.js' );
29
30
  var arrayFcn = require( './array.js' );
30
31
 
@@ -76,7 +77,7 @@ var arrayFcn = require( './array.js' );
76
77
  */
77
78
  function reduce( arr, initial, reducer, thisArg ) {
78
79
  if ( !isFunction( reducer ) ) {
79
- throw new TypeError( 'invalid argument. Third argument must be a function. Value:`' + reducer + '`.' );
80
+ throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', reducer ) );
80
81
  }
81
82
  if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like
82
83
  return ndarrayFcn( ndarraylike2object( arr ), initial, reducer, thisArg ); // eslint-disable-line max-len
@@ -84,7 +85,7 @@ function reduce( arr, initial, reducer, thisArg ) {
84
85
  if ( isArrayLikeObject( arr ) ) {
85
86
  return arrayFcn( arraylike2object( arr ), initial, reducer, thisArg );
86
87
  }
87
- throw new TypeError( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `' + arr + '`.' );
88
+ throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );
88
89
  }
89
90
 
90
91
 
package/lib/ndarray.js CHANGED
@@ -43,7 +43,7 @@ var MODE = 'throw';
43
43
  * @param {IntegerArray} x.strides - stride lengths
44
44
  * @param {NonNegativeInteger} x.offset - index offset
45
45
  * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
46
- * @param {Function} x.getter - callback for accessing `x` data buffer elements
46
+ * @param {Array<Function>} x.accessors - accessors for accessing data buffer elements
47
47
  * @param {*} initial - initial value
48
48
  * @param {Function} fcn - function to apply
49
49
  * @param {*} thisArg - function execution context
@@ -84,7 +84,7 @@ var MODE = 'throw';
84
84
  * 'strides': sx,
85
85
  * 'offset': ox,
86
86
  * 'order': 'row-major',
87
- * 'getter': getter
87
+ * 'accessors': [ getter ]
88
88
  * };
89
89
  * x.ref = x;
90
90
  *
@@ -129,7 +129,7 @@ function reduce( x, initial, fcn, thisArg ) {
129
129
  ordx = x.order;
130
130
 
131
131
  // Cache the element accessor:
132
- get = x.getter;
132
+ get = x.accessors[ 0 ];
133
133
 
134
134
  // Cache the reference to the original input array:
135
135
  ref = x.ref;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/utils-reduce",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "Apply a function against an accumulator and each element in an array and return the accumulated result.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,35 +37,37 @@
37
37
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@stdlib/array-base-arraylike2object": "^0.0.x",
41
- "@stdlib/assert-is-array-like-object": "^0.0.x",
42
- "@stdlib/assert-is-function": "^0.0.x",
43
- "@stdlib/assert-is-ndarray-like": "^0.0.x",
44
- "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x",
45
- "@stdlib/ndarray-base-vind2bind": "^0.0.x",
46
- "@stdlib/types": "^0.0.x"
40
+ "@stdlib/array-base-arraylike2object": "^0.1.0",
41
+ "@stdlib/assert-is-array-like-object": "^0.1.0",
42
+ "@stdlib/assert-is-function": "^0.1.0",
43
+ "@stdlib/assert-is-ndarray-like": "^0.1.0",
44
+ "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0",
45
+ "@stdlib/ndarray-base-vind2bind": "^0.1.0",
46
+ "@stdlib/string-format": "^0.1.0",
47
+ "@stdlib/types": "^0.1.0",
48
+ "@stdlib/error-tools-fmtprodmsg": "^0.1.0"
47
49
  },
48
50
  "devDependencies": {
49
- "@stdlib/array-base-filled": "^0.0.x",
50
- "@stdlib/array-complex64": "^0.0.x",
51
- "@stdlib/array-filled-by": "^0.0.x",
52
- "@stdlib/array-float64": "^0.0.x",
53
- "@stdlib/bench": "^0.0.x",
54
- "@stdlib/complex-float32": "^0.0.x",
55
- "@stdlib/complex-imagf": "^0.0.x",
56
- "@stdlib/complex-realf": "^0.0.x",
57
- "@stdlib/math-base-assert-is-nan": "^0.0.x",
58
- "@stdlib/math-base-ops-add": "^0.0.x",
59
- "@stdlib/math-base-ops-cadd": "^0.0.x",
60
- "@stdlib/math-base-special-pow": "^0.0.x",
61
- "@stdlib/ndarray-array": "^0.0.x",
62
- "@stdlib/ndarray-ctor": "^0.0.x",
63
- "@stdlib/random-base-discrete-uniform": "^0.0.x",
64
- "@stdlib/utils-nary-function": "^0.0.x",
65
- "@stdlib/utils-noop": "^0.0.x",
51
+ "@stdlib/array-base-filled": "^0.1.0",
52
+ "@stdlib/array-complex64": "^0.1.0",
53
+ "@stdlib/array-filled-by": "^0.0.2",
54
+ "@stdlib/array-float64": "^0.1.0",
55
+ "@stdlib/bench": "^0.1.0",
56
+ "@stdlib/complex-float32": "^0.1.0",
57
+ "@stdlib/complex-imagf": "^0.1.0",
58
+ "@stdlib/complex-realf": "^0.1.0",
59
+ "@stdlib/math-base-assert-is-nan": "^0.1.0",
60
+ "@stdlib/math-base-ops-add": "^0.1.0",
61
+ "@stdlib/math-base-ops-cadd": "^0.1.0",
62
+ "@stdlib/math-base-special-pow": "^0.1.0",
63
+ "@stdlib/ndarray-array": "^0.0.9",
64
+ "@stdlib/ndarray-ctor": "^0.1.0",
65
+ "@stdlib/random-base-discrete-uniform": "^0.0.6",
66
+ "@stdlib/utils-nary-function": "^0.1.0",
67
+ "@stdlib/utils-noop": "^0.1.0",
66
68
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
67
69
  "istanbul": "^0.4.1",
68
- "tap-spec": "5.x.x"
70
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
69
71
  },
70
72
  "engines": {
71
73
  "node": ">=0.10.0",
@@ -111,7 +113,7 @@
111
113
  "vector"
112
114
  ],
113
115
  "funding": {
114
- "type": "patreon",
115
- "url": "https://www.patreon.com/athan"
116
+ "type": "opencollective",
117
+ "url": "https://opencollective.com/stdlib"
116
118
  }
117
119
  }
package/docs/repl.txt DELETED
@@ -1,54 +0,0 @@
1
-
2
- {{alias}}( arr, initial, reducer[, thisArg] )
3
- Applies a function against an accumulator and each element in an array and
4
- returns the accumulated result.
5
-
6
- When invoked, the reduction function is provided four arguments:
7
-
8
- - accumulator: accumulated value.
9
- - value: array element.
10
- - index: element index.
11
- - arr: input array.
12
-
13
- If provided an empty array, the function returns the initial value.
14
-
15
- When provided an ndarray, the function performs a reduction over the entire
16
- input ndarray (i.e., higher-order ndarray dimensions are flattened to a
17
- single-dimension).
18
-
19
- Parameters
20
- ----------
21
- arr: ArrayLikeObject|ndarray
22
- Input array.
23
-
24
- initial: any
25
- Accumulator value used in the first invocation of the reduction
26
- function.
27
-
28
- reducer: Function
29
- Function to invoke for each element in the input array.
30
-
31
- thisArg: any (optional)
32
- Execution context.
33
-
34
- Returns
35
- -------
36
- out: any
37
- Accumulated result.
38
-
39
- Examples
40
- --------
41
- // array-like object:
42
- > var f = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 );
43
- > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
44
- > var out = {{alias}}( arr, 0.0, f )
45
- 21.0
46
-
47
- // ndarray:
48
- > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } );
49
- > out = {{alias}}( arr, 0.0, f )
50
- 21.0
51
-
52
- See Also
53
- --------
54
-
@@ -1,127 +0,0 @@
1
- /*
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2019 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- import array = require( '@stdlib/ndarray-array' );
20
- import reduce = require( './index' );
21
-
22
- /**
23
- * Callback function.
24
- *
25
- * @param acc - accumulated value
26
- * @param v - array element
27
- * @returns result
28
- */
29
- function clbk( acc: number, value: number ): number {
30
- return acc + value;
31
- }
32
-
33
-
34
- // TESTS //
35
-
36
- // The function returns the accumulated value when provided a collection...
37
- {
38
- reduce( [ 0, 1, 1, NaN, 2 ], 0, clbk ); // $ExpectType any
39
- reduce( [ -1, 1, 2 ], 100, clbk ); // $ExpectType any
40
- reduce( [ -1, 1, 2 ], 0, clbk, {} ); // $ExpectType any
41
- }
42
-
43
- // The function returns the accumulated value when provided an ndarray...
44
- {
45
- const arr = array( [ 1, 2, 3, 4, 5, 6 ] );
46
-
47
- reduce( arr, 0, clbk ); // $ExpectType any
48
- reduce( arr, 100, clbk ); // $ExpectType any
49
- reduce( arr, 0, clbk, {} ); // $ExpectType any
50
- }
51
-
52
- // The compiler throws an error if the function is provided a first argument which is not a collection or ndarray...
53
- {
54
- reduce( 2, 0, clbk ); // $ExpectError
55
- reduce( false, 0, clbk ); // $ExpectError
56
- reduce( true, 0, clbk ); // $ExpectError
57
- reduce( null, 0, clbk ); // $ExpectError
58
- reduce( {}, 0, clbk ); // $ExpectError
59
-
60
- reduce( 2, 0, clbk, {} ); // $ExpectError
61
- reduce( false, 0, clbk, {} ); // $ExpectError
62
- reduce( true, 0, clbk, {} ); // $ExpectError
63
- reduce( null, 0, clbk, {} ); // $ExpectError
64
- reduce( {}, 0, clbk, {} ); // $ExpectError
65
- }
66
-
67
- // The compiler throws an error if the function is provided a third argument which is not a function with a supported signature...
68
- {
69
- const arr1 = [ 0, 1, 1, NaN, 2 ];
70
-
71
- reduce( arr1, 0, 'abc' ); // $ExpectError
72
- reduce( arr1, 0, 2 ); // $ExpectError
73
- reduce( arr1, 0, false ); // $ExpectError
74
- reduce( arr1, 0, true ); // $ExpectError
75
- reduce( arr1, 0, null ); // $ExpectError
76
- reduce( arr1, 0, {} ); // $ExpectError
77
- reduce( arr1, 0, [] ); // $ExpectError
78
-
79
- reduce( arr1, 0, 'abc', {} ); // $ExpectError
80
- reduce( arr1, 0, 2, {} ); // $ExpectError
81
- reduce( arr1, 0, false, {} ); // $ExpectError
82
- reduce( arr1, 0, true, {} ); // $ExpectError
83
- reduce( arr1, 0, null, {} ); // $ExpectError
84
- reduce( arr1, 0, {}, {} ); // $ExpectError
85
- reduce( arr1, 0, [], {} ); // $ExpectError
86
-
87
- reduce( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
88
- reduce( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
89
-
90
- const arr2 = array( [ 0, 1, 1, NaN, 2 ] );
91
-
92
- reduce( arr2, 0, 'abc' ); // $ExpectError
93
- reduce( arr2, 0, 2 ); // $ExpectError
94
- reduce( arr2, 0, false ); // $ExpectError
95
- reduce( arr2, 0, true ); // $ExpectError
96
- reduce( arr2, 0, null ); // $ExpectError
97
- reduce( arr2, 0, {} ); // $ExpectError
98
- reduce( arr2, 0, [] ); // $ExpectError
99
-
100
- reduce( arr2, 0, 'abc', {} ); // $ExpectError
101
- reduce( arr2, 0, 2, {} ); // $ExpectError
102
- reduce( arr2, 0, false, {} ); // $ExpectError
103
- reduce( arr2, 0, true, {} ); // $ExpectError
104
- reduce( arr2, 0, null, {} ); // $ExpectError
105
- reduce( arr2, 0, {}, {} ); // $ExpectError
106
- reduce( arr2, 0, [], {} ); // $ExpectError
107
-
108
- reduce( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
109
- reduce( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
110
- }
111
-
112
- // The compiler throws an error if the function is provided an unsupported number of arguments...
113
- {
114
- const arr1 = [ 1, 2, 3 ];
115
-
116
- reduce(); // $ExpectError
117
- reduce( arr1 ); // $ExpectError
118
- reduce( arr1, 0 ); // $ExpectError
119
- reduce( arr1, 0, clbk, {}, 3 ); // $ExpectError
120
-
121
- const arr2 = array( [ 1, 2, 3 ] );
122
-
123
- reduce(); // $ExpectError
124
- reduce( arr2 ); // $ExpectError
125
- reduce( arr2, 0 ); // $ExpectError
126
- reduce( arr2, 0, clbk, {}, 3 ); // $ExpectError
127
- }