@stdlib/utils-map-reduce 0.0.1 → 0.2.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/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-2024 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
  # mapReduce
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] -->
@@ -239,6 +250,14 @@ console.log( 'sum: %d', out );
239
250
 
240
251
  <section class="related">
241
252
 
253
+ * * *
254
+
255
+ ## See Also
256
+
257
+ - <span class="package-name">[`@stdlib/utils-map`][@stdlib/utils/map]</span><span class="delimiter">: </span><span class="description">apply a function to each element in an array and assign the result to an element in an output array.</span>
258
+ - <span class="package-name">[`@stdlib/utils-map-reduce-right`][@stdlib/utils/map-reduce-right]</span><span class="delimiter">: </span><span class="description">perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.</span>
259
+ - <span class="package-name">[`@stdlib/utils-reduce`][@stdlib/utils/reduce]</span><span class="delimiter">: </span><span class="description">apply a function against an accumulator and each element in an array and return the accumulated result.</span>
260
+
242
261
  </section>
243
262
 
244
263
  <!-- /.related -->
@@ -269,7 +288,7 @@ See [LICENSE][stdlib-license].
269
288
 
270
289
  ## Copyright
271
290
 
272
- Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
291
+ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
273
292
 
274
293
  </section>
275
294
 
@@ -282,8 +301,8 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
282
301
  [npm-image]: http://img.shields.io/npm/v/@stdlib/utils-map-reduce.svg
283
302
  [npm-url]: https://npmjs.org/package/@stdlib/utils-map-reduce
284
303
 
285
- [test-image]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml/badge.svg
286
- [test-url]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml
304
+ [test-image]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml/badge.svg?branch=v0.2.0
305
+ [test-url]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml?query=branch:v0.2.0
287
306
 
288
307
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-map-reduce/main.svg
289
308
  [coverage-url]: https://codecov.io/github/stdlib-js/utils-map-reduce?branch=main
@@ -295,27 +314,41 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
295
314
 
296
315
  -->
297
316
 
317
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
318
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
319
+
320
+ [stdlib]: https://github.com/stdlib-js/stdlib
321
+
322
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
323
+
298
324
  [umd]: https://github.com/umdjs/umd
299
325
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
300
326
 
301
327
  [deno-url]: https://github.com/stdlib-js/utils-map-reduce/tree/deno
328
+ [deno-readme]: https://github.com/stdlib-js/utils-map-reduce/blob/deno/README.md
302
329
  [umd-url]: https://github.com/stdlib-js/utils-map-reduce/tree/umd
330
+ [umd-readme]: https://github.com/stdlib-js/utils-map-reduce/blob/umd/README.md
303
331
  [esm-url]: https://github.com/stdlib-js/utils-map-reduce/tree/esm
332
+ [esm-readme]: https://github.com/stdlib-js/utils-map-reduce/blob/esm/README.md
333
+ [branches-url]: https://github.com/stdlib-js/utils-map-reduce/blob/main/branches.md
304
334
 
305
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
306
- [chat-url]: https://gitter.im/stdlib-js/stdlib/
335
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce/main/LICENSE
307
336
 
308
- [stdlib]: https://github.com/stdlib-js/stdlib
337
+ [@stdlib/ndarray/ctor]: https://www.npmjs.com/package/@stdlib/ndarray-ctor
309
338
 
310
- [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
339
+ [@stdlib/array/complex64]: https://www.npmjs.com/package/@stdlib/array-complex64
311
340
 
312
- [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce/main/LICENSE
341
+ [@stdlib/array/complex128]: https://www.npmjs.com/package/@stdlib/array-complex128
342
+
343
+ <!-- <related-links> -->
344
+
345
+ [@stdlib/utils/map]: https://www.npmjs.com/package/@stdlib/utils-map
313
346
 
314
- [@stdlib/ndarray/ctor]: https://www.npmjs.com/package/@stdlib/stdlib
347
+ [@stdlib/utils/map-reduce-right]: https://www.npmjs.com/package/@stdlib/utils-map-reduce-right
315
348
 
316
- [@stdlib/array/complex64]: https://www.npmjs.com/package/@stdlib/stdlib
349
+ [@stdlib/utils/reduce]: https://www.npmjs.com/package/@stdlib/utils-reduce
317
350
 
318
- [@stdlib/array/complex128]: https://www.npmjs.com/package/@stdlib/stdlib
351
+ <!-- </related-links> -->
319
352
 
320
353
  </section>
321
354
 
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import mapReduce from '../docs/types/index';
3
+ export = mapReduce;
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";var y=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=y(function(H,g){
2
+ var T=require('@stdlib/ndarray-base-vind2bind/dist'),p="throw";function x(r,e,a,t,s){var n,v,i,u,f,c,l,m,d,q,o;if(u=r.length,l=r.shape,n=r.data,m=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(n,d),0,c),0,c);for(i=e,o=0;o<u;o++)q=T(l,m,d,v,o,p),i=t.call(s,i,a(f(n,q),o,c),o,c);return i}g.exports=x
3
+ });var k=y(function(I,w){
4
+ function R(r,e,a,t,s){var n,v,i,u;for(n=r.data,v=r.accessors[0],i=e,u=0;u<n.length;u++)i=t.call(s,i,a(v(n,u),u,n),u,n);return i}w.exports=R
5
+ });var E=y(function(J,j){
6
+ var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),b=require('@stdlib/error-tools-fmtprodmsg/dist'),M=h(),z=k();function B(r,e,a,t,s){if(!F(a))throw new TypeError(b('1VN3N',a));if(!F(t))throw new TypeError(b('1VN32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(b('1VNBH',r))}j.exports=B
7
+ });var C=E();module.exports=C;
8
+ /** @license Apache-2.0 */
9
+ //# 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) 2022 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* Performs a map-reduce operation against 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} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing 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 cceil = require( '@stdlib/math-base-special-cceil' );\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.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\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 = mapReduce( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduce( x, initial, mapper, reducer, 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 reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\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 = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Performs a map-reduce operation against 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} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\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 of squared values:\n* var out = mapReduce( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduce( x, initial, mapper, reducer, 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 = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Performs a map-reduce operation against each element in an array and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current 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} mapper - mapping function\n* @param {Function} reducer - reducing 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* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduce( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\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 = mapReduce( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduce( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth 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, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\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 = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce\n*\n* @example\n* var mapReduce = require( '@stdlib/utils-map-reduce' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduce( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduce = require( '@stdlib/utils-map-reduce' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduce( arr, 0, naryFunction( abs, 1 ), 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,QA0EX,SAASC,EAAWC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC1D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAI,EAAGA,EAAIP,EAAKO,IACrBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAWC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC1D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7BD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,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,IA6Df,SAASC,EAAWC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CAC5D,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduce", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduce", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduce", "arr", "initial", "mapper", "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
  * Callback invoked for each array element.
28
28
  *
29
29
  * @returns result
30
30
  */
31
- type Nullary = () => any;
31
+ type Nullary<U> = () => U;
32
32
 
33
33
  /**
34
34
  * Callback invoked for each array element.
@@ -36,7 +36,7 @@ type Nullary = () => any;
36
36
  * @param value - array element
37
37
  * @returns result
38
38
  */
39
- type Unary = ( value: any ) => any;
39
+ type Unary<T, U> = ( value: T ) => U;
40
40
 
41
41
  /**
42
42
  * Callback invoked for each array element.
@@ -45,7 +45,7 @@ type Unary = ( value: any ) => any;
45
45
  * @param index - element index
46
46
  * @returns result
47
47
  */
48
- type Binary = ( value: any, index: number ) => any;
48
+ type Binary<T, U> = ( value: T, index: number ) => U;
49
49
 
50
50
  /**
51
51
  * Callback invoked for each array element.
@@ -55,7 +55,7 @@ type Binary = ( value: any, index: number ) => any;
55
55
  * @param arr - array
56
56
  * @returns result
57
57
  */
58
- type Ternary = ( value: any, index: number, arr: ndarray ) => any;
58
+ type Ternary<T, U> = ( value: T, index: number, arr: typedndarray<T> ) => U;
59
59
 
60
60
  /**
61
61
  * Callback invoked for each array element.
@@ -65,7 +65,7 @@ type Ternary = ( value: any, index: number, arr: ndarray ) => any;
65
65
  * @param arr - array
66
66
  * @returns result
67
67
  */
68
- type ArrayTernary = ( value: any, index: number, arr: Collection ) => any;
68
+ type ArrayTernary<T, U> = ( value: T, index: number, arr: Collection<T> ) => U;
69
69
 
70
70
  /**
71
71
  * Callback invoked for each array element.
@@ -75,7 +75,7 @@ type ArrayTernary = ( value: any, index: number, arr: Collection ) => any;
75
75
  * @param arr - array
76
76
  * @returns result
77
77
  */
78
- type Mapper = Nullary | Unary | Binary | Ternary;
78
+ type Mapper<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
79
79
 
80
80
  /**
81
81
  * Callback invoked for each array element.
@@ -85,14 +85,14 @@ type Mapper = Nullary | Unary | Binary | Ternary;
85
85
  * @param arr - array
86
86
  * @returns result
87
87
  */
88
- type ArrayMapper = Nullary | Unary | Binary | ArrayTernary;
88
+ type ArrayMapper<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | ArrayTernary<T, U>;
89
89
 
90
90
  /**
91
91
  * Function applied against an accumulator.
92
92
  *
93
93
  * @returns accumulator value
94
94
  */
95
- type NullaryReducer = () => void;
95
+ type NullaryReducer<V, W> = ( this: W ) => V;
96
96
 
97
97
  /**
98
98
  * Function applied against an accumulator.
@@ -100,7 +100,7 @@ type NullaryReducer = () => void;
100
100
  * @param accumulator - accumulated value
101
101
  * @returns accumulator value
102
102
  */
103
- type UnaryReducer = ( accumulator: any ) => any;
103
+ type UnaryReducer<V, W> = ( this: W, accumulator: V ) => V;
104
104
 
105
105
  /**
106
106
  * Function applied against an accumulator.
@@ -109,7 +109,7 @@ type UnaryReducer = ( accumulator: any ) => any;
109
109
  * @param value - array element
110
110
  * @returns accumulator value
111
111
  */
112
- type BinaryReducer = ( accumulator: any, value: any ) => any;
112
+ type BinaryReducer<U, V, W> = ( this: W, accumulator: V, value: U ) => V;
113
113
 
114
114
  /**
115
115
  * Function applied against an accumulator.
@@ -119,7 +119,7 @@ type BinaryReducer = ( accumulator: any, value: any ) => any;
119
119
  * @param index - element index
120
120
  * @returns accumulator value
121
121
  */
122
- type TernaryReducer = ( accumulator: any, value: any, index: number ) => any;
122
+ type TernaryReducer<U, V, W> = ( this: W, accumulator: V, value: U, index: number ) => V;
123
123
 
124
124
  /**
125
125
  * Function applied against an accumulator.
@@ -130,7 +130,7 @@ type TernaryReducer = ( accumulator: any, value: any, index: number ) => any;
130
130
  * @param arr - array
131
131
  * @returns accumulator value
132
132
  */
133
- type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length
133
+ type QuaternaryReducer<U, V, T, W> = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray<T> ) => V;
134
134
 
135
135
  /**
136
136
  * Function applied against an accumulator.
@@ -141,7 +141,7 @@ type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: nda
141
141
  * @param arr - array
142
142
  * @returns accumulator value
143
143
  */
144
- type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length
144
+ type ArrayQuaternaryReducer<U, V, T, W> = ( this: W, accumulator: V, value: U, index: number, arr: Collection<T> ) => V;
145
145
 
146
146
  /**
147
147
  * Function applied against an accumulator.
@@ -152,7 +152,7 @@ type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr
152
152
  * @param arr - array
153
153
  * @returns accumulator value
154
154
  */
155
- type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length
155
+ type Reducer<U, V, T, W> = NullaryReducer<V, W> | UnaryReducer<V, W> | BinaryReducer<U, V, W> | TernaryReducer<U, V, W> | QuaternaryReducer<U, V, T, W>;
156
156
 
157
157
  /**
158
158
  * Function applied against an accumulator.
@@ -163,7 +163,7 @@ type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer |
163
163
  * @param arr - array
164
164
  * @returns accumulator value
165
165
  */
166
- type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length
166
+ type ArrayReducer<U, V, T, W> = NullaryReducer<V, W> | UnaryReducer<V, W> | BinaryReducer<U, V, W> | TernaryReducer<U, V, W> | ArrayQuaternaryReducer<U, V, T, W>;
167
167
 
168
168
  /**
169
169
  * Performs a map-reduce operation for each element in an array and returns the accumulated result.
@@ -193,10 +193,10 @@ type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReduc
193
193
  * @returns accumulated result
194
194
  *
195
195
  * @example
196
- * var naryFunction = require( `@stdlib/utils/nary-function` );
197
- * var abs = require( `@stdlib/math/base/special/abs` );
198
- * var add = require( `@stdlib/math/base/ops/add` );
199
- * var array = require( `@stdlib/ndarray/array` );
196
+ * var naryFunction = require( '@stdlib/utils-nary-function' );
197
+ * var abs = require( '@stdlib/math-base-special-abs' );
198
+ * var add = require( '@stdlib/math-base-ops-add' );
199
+ * var array = require( '@stdlib/ndarray-array' );
200
200
  *
201
201
  * var opts = {
202
202
  * 'dtype': 'generic'
@@ -206,7 +206,7 @@ type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReduc
206
206
  * var out = mapReduce( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) );
207
207
  * // returns 21
208
208
  */
209
- declare function mapReduce( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length
209
+ declare function mapReduce<T = unknown, U = unknown, V = unknown, W = unknown>( arr: typedndarray<T>, initial: V, mapper: Mapper<T, U>, reducer: Reducer<U, V, T, W>, thisArg?: ThisParameterType<Reducer<U, V, T, W>> ): V;
210
210
 
211
211
  /**
212
212
  * Performs a map-reduce operation for each element in an array and returns the accumulated result.
@@ -249,7 +249,7 @@ declare function mapReduce( arr: ndarray, initial: any, mapper: Mapper, reducer:
249
249
  * var out = mapReduce( arr, 0, square, sum );
250
250
  * // returns 30
251
251
  */
252
- declare function mapReduce( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length
252
+ declare function mapReduce<T = unknown, U = unknown, V = unknown, W = unknown>( arr: Collection<T>, initial: V, mapper: ArrayMapper<T, U>, reducer: ArrayReducer<U, V, T, W>, thisArg?: ThisParameterType<ArrayReducer<U, V, T, W>> ): V;
253
253
 
254
254
 
255
255
  // 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} mapper - mapping function
32
32
  * @param {Function} reducer - reducing function
@@ -50,7 +50,7 @@
50
50
  * // Create the input array object:
51
51
  * var x = {
52
52
  * 'data': [ 1, 2, 3, 4 ],
53
- * 'getter': getter
53
+ * 'accessors': [ getter ]
54
54
  * };
55
55
  *
56
56
  * // Compute the sum of squared values:
@@ -67,7 +67,7 @@ function mapReduce( x, initial, mapper, reducer, thisArg ) {
67
67
  xbuf = x.data;
68
68
 
69
69
  // Cache the element accessor:
70
- get = x.getter;
70
+ get = x.accessors[ 0 ];
71
71
 
72
72
  // Iterate over each element...
73
73
  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
 
@@ -89,10 +90,10 @@ var arrayFcn = require( './array.js' );
89
90
  */
90
91
  function mapReduce( arr, initial, mapper, reducer, thisArg ) {
91
92
  if ( !isFunction( mapper ) ) {
92
- throw new TypeError( 'invalid argument. Third argument must be a function. Value:`' + mapper + '`.' );
93
+ throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );
93
94
  }
94
95
  if ( !isFunction( reducer ) ) {
95
- throw new TypeError( 'invalid argument. Fourth argument must be a function. Value:`' + reducer + '`.' );
96
+ throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );
96
97
  }
97
98
  if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like
98
99
  return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len
@@ -100,7 +101,7 @@ function mapReduce( arr, initial, mapper, reducer, thisArg ) {
100
101
  if ( isArrayLikeObject( arr ) ) {
101
102
  return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len
102
103
  }
103
- throw new TypeError( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `' + arr + '`.' );
104
+ throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );
104
105
  }
105
106
 
106
107
 
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} mapper - mapping function
49
49
  * @param {Function} reducer - reducing function
@@ -86,7 +86,7 @@ var MODE = 'throw';
86
86
  * 'strides': sx,
87
87
  * 'offset': ox,
88
88
  * 'order': 'row-major',
89
- * 'getter': getter
89
+ * 'accessors': [ getter ]
90
90
  * };
91
91
  * x.ref = x;
92
92
  *
@@ -131,7 +131,7 @@ function mapReduce( x, initial, mapper, reducer, thisArg ) {
131
131
  ordx = x.order;
132
132
 
133
133
  // Cache the element accessor:
134
- get = x.getter;
134
+ get = x.accessors[ 0 ];
135
135
 
136
136
  // Cache the reference to the original input array:
137
137
  ref = x.ref;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/utils-map-reduce",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Perform a single-pass map-reduce operation against each element in an array and return the accumulated result.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,37 +37,40 @@
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.2.0",
41
+ "@stdlib/assert-is-array-like-object": "^0.2.0",
42
+ "@stdlib/assert-is-function": "^0.2.0",
43
+ "@stdlib/assert-is-ndarray-like": "^0.2.0",
44
+ "@stdlib/ndarray-base-ndarraylike2object": "^0.2.0",
45
+ "@stdlib/ndarray-base-vind2bind": "^0.2.0",
46
+ "@stdlib/string-format": "^0.2.0",
47
+ "@stdlib/types": "^0.3.1",
48
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.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-abs": "^0.0.x",
61
- "@stdlib/math-base-special-cceil": "^0.0.x",
62
- "@stdlib/math-base-special-pow": "^0.0.x",
63
- "@stdlib/ndarray-array": "^0.0.x",
64
- "@stdlib/ndarray-ctor": "^0.0.x",
65
- "@stdlib/random-base-discrete-uniform": "^0.0.x",
66
- "@stdlib/utils-nary-function": "^0.0.x",
67
- "@stdlib/utils-noop": "^0.0.x",
51
+ "@stdlib/array-base-filled": "^0.2.0",
52
+ "@stdlib/array-complex64": "^0.1.0",
53
+ "@stdlib/array-filled-by": "^0.1.0",
54
+ "@stdlib/array-float64": "^0.2.0",
55
+ "@stdlib/complex-float32": "^0.2.0",
56
+ "@stdlib/complex-imagf": "^0.2.0",
57
+ "@stdlib/complex-realf": "^0.2.0",
58
+ "@stdlib/math-base-assert-is-nan": "^0.2.0",
59
+ "@stdlib/math-base-ops-add": "^0.2.0",
60
+ "@stdlib/math-base-ops-cadd": "^0.2.0",
61
+ "@stdlib/math-base-special-abs": "^0.2.0",
62
+ "@stdlib/math-base-special-cceil": "^0.2.0",
63
+ "@stdlib/math-base-special-pow": "^0.2.0",
64
+ "@stdlib/ndarray-array": "^0.1.0",
65
+ "@stdlib/ndarray-ctor": "^0.1.0",
66
+ "@stdlib/random-base-discrete-uniform": "^0.1.0",
67
+ "@stdlib/utils-nary-function": "^0.2.0",
68
+ "@stdlib/utils-noop": "^0.2.0",
68
69
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
69
70
  "istanbul": "^0.4.1",
70
- "tap-spec": "5.x.x"
71
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
72
+ "@stdlib/bench-harness": "^0.2.0",
73
+ "@stdlib/bench": "^0.3.1"
71
74
  },
72
75
  "engines": {
73
76
  "node": ">=0.10.0",
@@ -117,7 +120,7 @@
117
120
  "vector"
118
121
  ],
119
122
  "funding": {
120
- "type": "patreon",
121
- "url": "https://www.patreon.com/athan"
123
+ "type": "opencollective",
124
+ "url": "https://opencollective.com/stdlib"
122
125
  }
123
126
  }
package/docs/repl.txt DELETED
@@ -1,65 +0,0 @@
1
-
2
- {{alias}}( arr, initial, mapper, reducer[, thisArg] )
3
- Performs a map-reduce operation for each element in an array and returns the
4
- accumulated result.
5
-
6
- When invoked, the mapping function is provided three arguments:
7
-
8
- - value: array element.
9
- - index: element index.
10
- - arr: input array.
11
-
12
- When invoked, the reducing function is provided four arguments:
13
-
14
- - accumulator: accumulated value.
15
- - value: result after applying the mapping function to the current array
16
- element.
17
- - index: element index.
18
- - arr: input array.
19
-
20
- If provided an empty array, the function returns the initial value.
21
-
22
- When provided an ndarray, the function performs a single-pass map-reduce
23
- operation over the entire input ndarray (i.e., higher-order ndarray
24
- dimensions are flattened to a single-dimension).
25
-
26
- Parameters
27
- ----------
28
- arr: ArrayLikeObject|ndarray
29
- Input array.
30
-
31
- initial: any
32
- Accumulator value used in the first invocation of the reduction
33
- function.
34
-
35
- mapper: Function
36
- Mapping function.
37
-
38
- reducer: Function
39
- Reducing function.
40
-
41
- thisArg: any (optional)
42
- Execution context for the reducing function.
43
-
44
- Returns
45
- -------
46
- out: any
47
- Accumulated result.
48
-
49
- Examples
50
- --------
51
- // array-like object:
52
- > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 );
53
- > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 );
54
- > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ];
55
- > var out = {{alias}}( arr, 0.0, f1, f2 )
56
- 21.0
57
-
58
- // ndarray:
59
- > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } );
60
- > out = {{alias}}( arr, 0.0, f1, f2 )
61
- 21.0
62
-
63
- See Also
64
- --------
65
-
@@ -1,184 +0,0 @@
1
- /*
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2022 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 mapReduce = require( './index' );
21
-
22
- /**
23
- * Mapping function.
24
- *
25
- * @param value - array element
26
- * @returns result
27
- */
28
- function mapper( value: number ): number {
29
- return value;
30
- }
31
-
32
- /**
33
- * Reducing function.
34
- *
35
- * @param acc - accumulated value
36
- * @param v - array element
37
- * @returns result
38
- */
39
- function reducer( acc: number, value: number ): number {
40
- return acc + value;
41
- }
42
-
43
-
44
- // TESTS //
45
-
46
- // The function returns the accumulated value when provided a collection...
47
- {
48
- mapReduce( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any
49
- mapReduce( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any
50
- mapReduce( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any
51
- }
52
-
53
- // The function returns the accumulated value when provided an ndarray...
54
- {
55
- const arr = array( [ 1, 2, 3, 4, 5, 6 ] );
56
-
57
- mapReduce( arr, 0, mapper, reducer ); // $ExpectType any
58
- mapReduce( arr, 100, mapper, reducer ); // $ExpectType any
59
- mapReduce( arr, 0, mapper, reducer, {} ); // $ExpectType any
60
- }
61
-
62
- // The compiler throws an error if the function is provided a first argument which is not a collection or ndarray...
63
- {
64
- mapReduce( 2, 0, mapper, reducer ); // $ExpectError
65
- mapReduce( false, 0, mapper, reducer ); // $ExpectError
66
- mapReduce( true, 0, mapper, reducer ); // $ExpectError
67
- mapReduce( null, 0, mapper, reducer ); // $ExpectError
68
- mapReduce( {}, 0, mapper, reducer ); // $ExpectError
69
-
70
- mapReduce( 2, 0, mapper, reducer, {} ); // $ExpectError
71
- mapReduce( false, 0, mapper, reducer, {} ); // $ExpectError
72
- mapReduce( true, 0, mapper, reducer, {} ); // $ExpectError
73
- mapReduce( null, 0, mapper, reducer, {} ); // $ExpectError
74
- mapReduce( {}, 0, mapper, reducer, {} ); // $ExpectError
75
- }
76
-
77
- // The compiler throws an error if the function is provided a third argument which is not a function with a supported signature...
78
- {
79
- const arr1 = [ 0, 1, 1, NaN, 2 ];
80
-
81
- mapReduce( arr1, 0, 'abc', reducer ); // $ExpectError
82
- mapReduce( arr1, 0, 2, reducer ); // $ExpectError
83
- mapReduce( arr1, 0, false, reducer ); // $ExpectError
84
- mapReduce( arr1, 0, true, reducer ); // $ExpectError
85
- mapReduce( arr1, 0, null, reducer ); // $ExpectError
86
- mapReduce( arr1, 0, {}, reducer ); // $ExpectError
87
- mapReduce( arr1, 0, [], reducer ); // $ExpectError
88
-
89
- mapReduce( arr1, 0, 'abc', reducer, {} ); // $ExpectError
90
- mapReduce( arr1, 0, 2, reducer, {} ); // $ExpectError
91
- mapReduce( arr1, 0, false, reducer, {} ); // $ExpectError
92
- mapReduce( arr1, 0, true, reducer, {} ); // $ExpectError
93
- mapReduce( arr1, 0, null, reducer, {} ); // $ExpectError
94
- mapReduce( arr1, 0, {}, reducer, {} ); // $ExpectError
95
- mapReduce( arr1, 0, [], reducer, {} ); // $ExpectError
96
-
97
- mapReduce( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError
98
- mapReduce( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError
99
-
100
- const arr2 = array( [ 0, 1, 1, NaN, 2 ] );
101
-
102
- mapReduce( arr2, 0, 'abc', reducer ); // $ExpectError
103
- mapReduce( arr2, 0, 2, reducer ); // $ExpectError
104
- mapReduce( arr2, 0, false, reducer ); // $ExpectError
105
- mapReduce( arr2, 0, true, reducer ); // $ExpectError
106
- mapReduce( arr2, 0, null, reducer ); // $ExpectError
107
- mapReduce( arr2, 0, {}, reducer ); // $ExpectError
108
- mapReduce( arr2, 0, [], reducer ); // $ExpectError
109
-
110
- mapReduce( arr2, 0, 'abc', reducer, {} ); // $ExpectError
111
- mapReduce( arr2, 0, 2, reducer, {} ); // $ExpectError
112
- mapReduce( arr2, 0, false, reducer, {} ); // $ExpectError
113
- mapReduce( arr2, 0, true, reducer, {} ); // $ExpectError
114
- mapReduce( arr2, 0, null, reducer, {} ); // $ExpectError
115
- mapReduce( arr2, 0, {}, reducer, {} ); // $ExpectError
116
- mapReduce( arr2, 0, [], reducer, {} ); // $ExpectError
117
-
118
- mapReduce( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError
119
- mapReduce( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError
120
- }
121
-
122
- // The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature...
123
- {
124
- const arr1 = [ 0, 1, 1, NaN, 2 ];
125
-
126
- mapReduce( arr1, 0, mapper, 'abc' ); // $ExpectError
127
- mapReduce( arr1, 0, mapper, 2 ); // $ExpectError
128
- mapReduce( arr1, 0, mapper, false ); // $ExpectError
129
- mapReduce( arr1, 0, mapper, true ); // $ExpectError
130
- mapReduce( arr1, 0, mapper, null ); // $ExpectError
131
- mapReduce( arr1, 0, mapper, {} ); // $ExpectError
132
- mapReduce( arr1, 0, mapper, [] ); // $ExpectError
133
-
134
- mapReduce( arr1, 0, mapper, 'abc', {} ); // $ExpectError
135
- mapReduce( arr1, 0, mapper, 2, {} ); // $ExpectError
136
- mapReduce( arr1, 0, mapper, false, {} ); // $ExpectError
137
- mapReduce( arr1, 0, mapper, true, {} ); // $ExpectError
138
- mapReduce( arr1, 0, mapper, null, {} ); // $ExpectError
139
- mapReduce( arr1, 0, mapper, {}, {} ); // $ExpectError
140
- mapReduce( arr1, 0, mapper, [], {} ); // $ExpectError
141
-
142
- mapReduce( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
143
- mapReduce( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
144
-
145
- const arr2 = array( [ 0, 1, 1, NaN, 2 ] );
146
-
147
- mapReduce( arr2, 0, mapper, 'abc' ); // $ExpectError
148
- mapReduce( arr2, 0, mapper, 2 ); // $ExpectError
149
- mapReduce( arr2, 0, mapper, false ); // $ExpectError
150
- mapReduce( arr2, 0, mapper, true ); // $ExpectError
151
- mapReduce( arr2, 0, mapper, null ); // $ExpectError
152
- mapReduce( arr2, 0, mapper, {} ); // $ExpectError
153
- mapReduce( arr2, 0, mapper, [] ); // $ExpectError
154
-
155
- mapReduce( arr2, 0, mapper, 'abc', {} ); // $ExpectError
156
- mapReduce( arr2, 0, mapper, 2, {} ); // $ExpectError
157
- mapReduce( arr2, 0, mapper, false, {} ); // $ExpectError
158
- mapReduce( arr2, 0, mapper, true, {} ); // $ExpectError
159
- mapReduce( arr2, 0, mapper, null, {} ); // $ExpectError
160
- mapReduce( arr2, 0, mapper, {}, {} ); // $ExpectError
161
- mapReduce( arr2, 0, mapper, [], {} ); // $ExpectError
162
-
163
- mapReduce( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
164
- mapReduce( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
165
- }
166
-
167
- // The compiler throws an error if the function is provided an unsupported number of arguments...
168
- {
169
- const arr1 = [ 1, 2, 3 ];
170
-
171
- mapReduce(); // $ExpectError
172
- mapReduce( arr1 ); // $ExpectError
173
- mapReduce( arr1, 0 ); // $ExpectError
174
- mapReduce( arr1, 0, mapper, ); // $ExpectError
175
- mapReduce( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError
176
-
177
- const arr2 = array( [ 1, 2, 3 ] );
178
-
179
- mapReduce(); // $ExpectError
180
- mapReduce( arr2 ); // $ExpectError
181
- mapReduce( arr2, 0 ); // $ExpectError
182
- mapReduce( arr2, 0, mapper ); // $ExpectError
183
- mapReduce( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError
184
- }