@stdlib/utils-map2-right 0.0.1

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.
@@ -0,0 +1,363 @@
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
+ // TypeScript Version: 2.0
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { Collection } from '@stdlib/types/object';
24
+ import { ndarray } from '@stdlib/types/ndarray';
25
+
26
+ /**
27
+ * Callback invoked for each pair of array elements.
28
+ *
29
+ * @returns result
30
+ */
31
+ type Nullary = () => any;
32
+
33
+ /**
34
+ * Callback invoked for each pair of array elements.
35
+ *
36
+ * @param v1 - element from the first input array
37
+ * @returns result
38
+ */
39
+ type Unary = ( v1: any ) => any;
40
+
41
+ /**
42
+ * Callback invoked for each pair of array elements.
43
+ *
44
+ * @param v1 - element from the first input array
45
+ * @param v2 - element from the second input array
46
+ * @returns result
47
+ */
48
+ type Binary = ( v1: any, v2: any ) => any;
49
+
50
+ /**
51
+ * Callback invoked for each pair of array elements.
52
+ *
53
+ * @param v1 - element from the first input array
54
+ * @param v2 - element from the second input array
55
+ * @param index - element index
56
+ * @returns result
57
+ */
58
+ type Ternary = ( v1: any, v2: any, index: number ) => any;
59
+
60
+ /**
61
+ * Callback invoked for each pair of array elements.
62
+ *
63
+ * @param v1 - element from the first input array
64
+ * @param v2 - element from the second input array
65
+ * @param index - element index
66
+ * @param x - first input array
67
+ * @returns result
68
+ */
69
+ type Quaternary = ( v1: any, v2: any, index: number, x: ndarray ) => any;
70
+
71
+ /**
72
+ * Callback invoked for each pair of array elements.
73
+ *
74
+ * @param v1 - element from the first input array
75
+ * @param v2 - element from the second input array
76
+ * @param index - element index
77
+ * @param x - first input array
78
+ * @returns result
79
+ */
80
+ type ArrayQuaternary = ( v1: any, v2: any, index: number, x: Collection ) => any; // tslint:disable-line:max-line-length
81
+
82
+ /**
83
+ * Callback invoked for each pair of array elements.
84
+ *
85
+ * @param v1 - element from the first input array
86
+ * @param v2 - element from the second input array
87
+ * @param index - element index
88
+ * @param x - first input array
89
+ * @param y - second input array
90
+ * @returns result
91
+ */
92
+ type Quinary = ( v1: any, v2: any, index: number, x: ndarray, y: ndarray ) => any; // tslint:disable-line:max-line-length
93
+
94
+ /**
95
+ * Callback invoked for each pair of array elements.
96
+ *
97
+ * @param v1 - element from the first input array
98
+ * @param v2 - element from the second input array
99
+ * @param index - element index
100
+ * @param x - first input array
101
+ * @param y - second input array
102
+ * @returns result
103
+ */
104
+ type ArrayQuinary = ( v1: any, v2: any, index: number, x: Collection, y: Collection ) => any; // tslint:disable-line:max-line-length
105
+
106
+ /**
107
+ * Callback invoked for each pair of array elements.
108
+ *
109
+ * @param v1 - element from the first input array
110
+ * @param v2 - element from the second input array
111
+ * @param index - element index
112
+ * @param x - first input array
113
+ * @param y - second input array
114
+ * @returns result
115
+ */
116
+ type Callback = Nullary | Unary | Binary | Ternary | Quaternary | Quinary;
117
+
118
+ /**
119
+ * Callback invoked for each pair of array elements.
120
+ *
121
+ * @param v1 - element from the first input array
122
+ * @param v2 - element from the second input array
123
+ * @param index - element index
124
+ * @param x - first input array
125
+ * @param y - second input array
126
+ * @returns result
127
+ */
128
+ type ArrayCallback = Nullary | Unary | Binary | Ternary | ArrayQuaternary | ArrayQuinary; // tslint:disable-line:max-line-length
129
+
130
+ /**
131
+ * Interface describing the main export.
132
+ */
133
+ interface Routine {
134
+ // NOTE: signature order matters here, as an ndarray is an array-like object...
135
+
136
+ /**
137
+ * Applies a function to elements in two input arrays while iterating from right to left and assigns the results to a new array.
138
+ *
139
+ * ## Notes
140
+ *
141
+ * - The applied function is provided the following arguments:
142
+ *
143
+ * - **v1**: element from first input array.
144
+ * - **v2**: element from second input array.
145
+ * - **idx**: element index.
146
+ * - **x**: first input array.
147
+ * - **y**: second input array.
148
+ *
149
+ * @param x - first input array
150
+ * @param y - second input array
151
+ * @param fcn - function to apply
152
+ * @param thisArg - input function context
153
+ * @returns output array
154
+ *
155
+ * @example
156
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
157
+ * var add = require( `@stdlib/math/base/ops/add` );
158
+ * var array = require( `@stdlib/ndarray/array` );
159
+ *
160
+ * var opts = {
161
+ * 'dtype': 'generic'
162
+ * };
163
+ * var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );
164
+ * var y = array( [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], opts );
165
+ *
166
+ * var out = map2Right( x, y, naryFunction( add, 2 ) );
167
+ * // returns <ndarray>
168
+ *
169
+ * var data = out.data;
170
+ * // returns [ 2, 3, 4, 5, 6, 7 ]
171
+ */
172
+ ( x: ndarray, y: ndarray, fcn: Callback, thisArg?: any ): ndarray;
173
+
174
+ /**
175
+ * Applies a function to elements in two input arrays while iterating from right to left and assigns the results to a new array.
176
+ *
177
+ * ## Notes
178
+ *
179
+ * - The applied function is provided the following arguments:
180
+ *
181
+ * - **v1**: element from first input array.
182
+ * - **v2**: element from second input array.
183
+ * - **idx**: element index.
184
+ * - **x**: first input array.
185
+ * - **y**: second input array.
186
+ *
187
+ * @param x - first input array
188
+ * @param y - second input array
189
+ * @param fcn - function to apply
190
+ * @param thisArg - input function context
191
+ * @returns output array
192
+ *
193
+ * @example
194
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
195
+ * var add = require( `@stdlib/math/base/ops/add` );
196
+ *
197
+ * var x = [ 1, 2, 3, 4, 5, 6 ];
198
+ * var y = [ 1, 1, 1, 1, 1, 1 ];
199
+ *
200
+ * var out = map2Right( x, y, naryFunction( add, 2 ) );
201
+ * // returns [ 2, 3, 4, 5, 6, 7 ]
202
+ */
203
+ ( x: Collection, y: Collection, fcn: ArrayCallback, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
204
+
205
+ /**
206
+ * Applies a function to elements in two input arrays while iterating from right to left and assigns the results to an output array.
207
+ *
208
+ * ## Notes
209
+ *
210
+ * - The applied function is provided the following arguments:
211
+ *
212
+ * - **v1**: element from first input array.
213
+ * - **v2**: element from second input array.
214
+ * - **idx**: element index.
215
+ * - **x**: first input array.
216
+ * - **y**: second input array.
217
+ *
218
+ * @param x - first input array
219
+ * @param y - second input array
220
+ * @param out - output array
221
+ * @param fcn - function to apply
222
+ * @param thisArg - input function context
223
+ * @returns output array
224
+ *
225
+ * @example
226
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
227
+ * var add = require( `@stdlib/math/base/ops/add` );
228
+ * var array = require( `@stdlib/ndarray/array` );
229
+ *
230
+ * var opts = {
231
+ * 'dtype': 'generic',
232
+ * 'shape': [ 2, 3 ]
233
+ * };
234
+ * var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );
235
+ * var y = array( [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], opts );
236
+ * var out = array( opts );
237
+ *
238
+ * map2Right.assign( x, y, out, naryFunction( add, 2 ) );
239
+ *
240
+ * var data = out.data;
241
+ * // returns [ 2, 3, 4, 5, 6, 7 ]
242
+ */
243
+ assign( x: ndarray, y: ndarray, out: ndarray, fcn: Callback, thisArg?: any ): ndarray; // tslint:disable-line:max-line-length
244
+
245
+ /**
246
+ * Applies a function to elements in two input arrays while iterating from right to left and assigns the results to an output array.
247
+ *
248
+ * ## Notes
249
+ *
250
+ * - The applied function is provided the following arguments:
251
+ *
252
+ * - **v1**: element from first input array.
253
+ * - **v2**: element from second input array.
254
+ * - **idx**: element index.
255
+ * - **x**: first input array.
256
+ * - **y**: second input array.
257
+ *
258
+ * @param x - first input array
259
+ * @param y - second input array
260
+ * @param out - output array
261
+ * @param fcn - function to apply
262
+ * @param thisArg - input function context
263
+ * @returns output array
264
+ *
265
+ * @example
266
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
267
+ * var add = require( `@stdlib/math/base/ops/add` );
268
+ *
269
+ * var x = [ 1, 2, 3, 4, 5, 6 ];
270
+ * var y = [ 1, 1, 1, 1, 1, 1 ];
271
+ * var out = [ 0, 0, 0, 0, 0, 0 ];
272
+ *
273
+ * map2Right.assign( x, y, out, naryFunction( add, 2 ) );
274
+ *
275
+ * console.log( out );
276
+ * // => [ 2, 3, 4, 5, 6, 7 ]
277
+ */
278
+ assign( x: Collection, y: Collection, out: Collection, fcn: ArrayCallback, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
279
+ }
280
+
281
+ /**
282
+ * Applies a function to elements in two input arrays while iterating from right to left and assigns the results to a new array.
283
+ *
284
+ * ## Notes
285
+ *
286
+ * - The applied function is provided the following arguments:
287
+ *
288
+ * - **v1**: element from first input array.
289
+ * - **v2**: element from second input array.
290
+ * - **idx**: element index.
291
+ * - **x**: first input array.
292
+ * - **y**: second input array.
293
+ *
294
+ * @param x - first input array
295
+ * @param y - second input array
296
+ * @param fcn - function to apply
297
+ * @param thisArg - input function context
298
+ * @returns output array
299
+ *
300
+ * @example
301
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
302
+ * var add = require( `@stdlib/math/base/ops/add` );
303
+ *
304
+ * var x = [ 1, 2, 3, 4, 5, 6 ];
305
+ * var y = [ 1, 1, 1, 1, 1, 1 ];
306
+ *
307
+ * var out = map2Right( x, y, naryFunction( add, 2 ) );
308
+ * // returns [ 2, 3, 4, 5, 6, 7 ]
309
+ *
310
+ * @example
311
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
312
+ * var add = require( `@stdlib/math/base/ops/add` );
313
+ * var array = require( `@stdlib/ndarray/array` );
314
+ *
315
+ * var opts = {
316
+ * 'dtype': 'generic'
317
+ * };
318
+ * var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );
319
+ * var y = array( [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], opts );
320
+ *
321
+ * var out = map2Right( x, y, naryFunction( add, 2 ) );
322
+ * // returns <ndarray>
323
+ *
324
+ * var data = out.data;
325
+ * // returns [ 2, 3, 4, 5, 6, 7 ]
326
+ *
327
+ * @example
328
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
329
+ * var add = require( `@stdlib/math/base/ops/add` );
330
+ *
331
+ * var x = [ 1, 2, 3, 4, 5, 6 ];
332
+ * var y = [ 1, 1, 1, 1, 1, 1 ];
333
+ * var out = [ 0, 0, 0, 0, 0, 0 ];
334
+ *
335
+ * map2Right.assign( x, y, out, naryFunction( add, 2 ) );
336
+ *
337
+ * console.log( out );
338
+ * // => [ 2, 3, 4, 5, 6, 7 ]
339
+ *
340
+ * @example
341
+ * var naryFunction = require( `@stdlib/utils/nary-function` );
342
+ * var add = require( `@stdlib/math/base/ops/add` );
343
+ * var array = require( `@stdlib/ndarray/array` );
344
+ *
345
+ * var opts = {
346
+ * 'dtype': 'generic',
347
+ * 'shape': [ 2, 3 ]
348
+ * };
349
+ * var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );
350
+ * var y = array( [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], opts );
351
+ * var out = array( opts );
352
+ *
353
+ * map2Right.assign( x, y, out, naryFunction( add, 2 ) );
354
+ *
355
+ * var data = out.data;
356
+ * // returns [ 2, 3, 4, 5, 6, 7 ]
357
+ */
358
+ declare var map2Right: Routine;
359
+
360
+
361
+ // EXPORTS //
362
+
363
+ export = map2Right;
@@ -0,0 +1,343 @@
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 map2Right = require( './index' );
21
+
22
+ /**
23
+ * Callback function.
24
+ *
25
+ * @param v1 - first value
26
+ * @param v2 - second value
27
+ * @returns result
28
+ */
29
+ function clbk( v1: number, v2: number ): number {
30
+ return v1 + v2;
31
+ }
32
+
33
+
34
+ // TESTS //
35
+
36
+ // The function returns a collection when provided collections...
37
+ {
38
+ const x = [ 1, 2, 3, 4, 5, 6 ];
39
+ const y = [ 1, 1, 1, 1, 1, 1 ];
40
+
41
+ map2Right( x, y, clbk ); // $ExpectType Collection
42
+ map2Right( x, y, clbk, {} ); // $ExpectType Collection
43
+ }
44
+
45
+ // The function returns an ndarray when provided ndarrays...
46
+ {
47
+ const x = array( [ 1, 2, 3, 4, 5, 6 ] );
48
+ const y = array( [ 1, 1, 1, 1, 1, 1 ] );
49
+
50
+ map2Right( x, y, clbk ); // $ExpectType ndarray
51
+ map2Right( x, y, clbk, {} ); // $ExpectType ndarray
52
+ }
53
+
54
+ // The compiler throws an error if the function is provided a first argument other than a collection or ndarray...
55
+ {
56
+ const y = [ 1, 1, 1, 1, 1, 1 ];
57
+
58
+ map2Right( 5, y, clbk ); // $ExpectError
59
+ map2Right( true, y, clbk ); // $ExpectError
60
+ map2Right( false, y, clbk ); // $ExpectError
61
+ map2Right( null, y, clbk, {} ); // $ExpectError
62
+ map2Right( {}, y, clbk ); // $ExpectError
63
+
64
+ map2Right( 5, y, clbk, {} ); // $ExpectError
65
+ map2Right( true, y, clbk, {} ); // $ExpectError
66
+ map2Right( false, y, clbk, {} ); // $ExpectError
67
+ map2Right( null, y, clbk, {} ); // $ExpectError
68
+ map2Right( {}, y, clbk, {} ); // $ExpectError
69
+ }
70
+
71
+ // The compiler throws an error if the function is provided a second argument other than a collection or ndarray...
72
+ {
73
+ const x = [ 1, 2, 3, 4, 5, 6 ];
74
+
75
+ map2Right( x, 5, clbk ); // $ExpectError
76
+ map2Right( x, true, clbk ); // $ExpectError
77
+ map2Right( x, false, clbk ); // $ExpectError
78
+ map2Right( x, null, clbk, {} ); // $ExpectError
79
+ map2Right( x, {}, clbk ); // $ExpectError
80
+
81
+ map2Right( x, 5, clbk, {} ); // $ExpectError
82
+ map2Right( x, true, clbk, {} ); // $ExpectError
83
+ map2Right( x, false, clbk, {} ); // $ExpectError
84
+ map2Right( x, null, clbk, {} ); // $ExpectError
85
+ map2Right( x, {}, clbk, {} ); // $ExpectError
86
+ }
87
+
88
+ // The compiler throws an error if the function is provided a third argument other than a function with a supported signature...
89
+ {
90
+ const x1 = [ 1, 2, 3, 4, 5, 6 ];
91
+ const y1 = [ 1, 1, 1, 1, 1, 1 ];
92
+
93
+ map2Right( x1, y1, '5' ); // $ExpectError
94
+ map2Right( x1, y1, true ); // $ExpectError
95
+ map2Right( x1, y1, false ); // $ExpectError
96
+ map2Right( x1, y1, 123 ); // $ExpectError
97
+ map2Right( x1, y1, null ); // $ExpectError
98
+ map2Right( x1, y1, {} ); // $ExpectError
99
+ map2Right( x1, y1, [] ); // $ExpectError
100
+
101
+ map2Right( x1, y1, '5', {} ); // $ExpectError
102
+ map2Right( x1, y1, true, {} ); // $ExpectError
103
+ map2Right( x1, y1, false, {} ); // $ExpectError
104
+ map2Right( x1, y1, 123, {} ); // $ExpectError
105
+ map2Right( x1, y1, null, {} ); // $ExpectError
106
+ map2Right( x1, y1, {}, {} ); // $ExpectError
107
+ map2Right( x1, y1, [], {} ); // $ExpectError
108
+
109
+ map2Right( x1, y1, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
110
+ map2Right( x1, y1, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
111
+
112
+ const x2 = array( [ 1, 2, 3, 4, 5, 6 ] );
113
+ const y2 = array( [ 1, 1, 1, 1, 1, 1 ] );
114
+
115
+ map2Right( x2, y2, '5' ); // $ExpectError
116
+ map2Right( x2, y2, true ); // $ExpectError
117
+ map2Right( x2, y2, false ); // $ExpectError
118
+ map2Right( x2, y2, 123 ); // $ExpectError
119
+ map2Right( x2, y2, null ); // $ExpectError
120
+ map2Right( x2, y2, {} ); // $ExpectError
121
+ map2Right( x2, y2, [] ); // $ExpectError
122
+
123
+ map2Right( x2, y2, '5', {} ); // $ExpectError
124
+ map2Right( x2, y2, true, {} ); // $ExpectError
125
+ map2Right( x2, y2, false, {} ); // $ExpectError
126
+ map2Right( x2, y2, 123, {} ); // $ExpectError
127
+ map2Right( x2, y2, null, {} ); // $ExpectError
128
+ map2Right( x2, y2, {}, {} ); // $ExpectError
129
+ map2Right( x2, y2, [], {} ); // $ExpectError
130
+
131
+ map2Right( x2, y2, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
132
+ map2Right( x2, y2, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
133
+ }
134
+
135
+ // The compiler throws an error if the function is provided an unsupported number of arguments...
136
+ {
137
+ const x1 = [ 1, 2, 3, 4, 5, 6 ];
138
+ const y1 = [ 1, 1, 1, 1, 1, 1 ];
139
+
140
+ map2Right(); // $ExpectError
141
+ map2Right( x1 ); // $ExpectError
142
+ map2Right( x1, y1 ); // $ExpectError
143
+ map2Right( x1, y1, clbk, {}, 4 ); // $ExpectError
144
+
145
+ const x2 = array( [ 1, 2, 3, 4, 5, 6 ] );
146
+ const y2 = array( [ 1, 1, 1, 1, 1, 1 ] );
147
+
148
+ map2Right(); // $ExpectError
149
+ map2Right( x2 ); // $ExpectError
150
+ map2Right( x2, y2 ); // $ExpectError
151
+ map2Right( x2, y2, clbk, {}, 4 ); // $ExpectError
152
+ }
153
+
154
+ // Attached to the main export is an `assign` method which returns a collection when provided collections...
155
+ {
156
+ const x = [ 1, 2, 3, 4, 5, 6 ];
157
+ const y = [ 1, 1, 1, 1, 1, 1 ];
158
+ const out = [ 0, 0, 0, 0, 0, 0 ];
159
+
160
+ map2Right.assign( x, y, out, clbk ); // $ExpectType Collection
161
+ map2Right.assign( x, y, out, clbk, {} ); // $ExpectType Collection
162
+ }
163
+
164
+ // The `assign` method returns an ndarray when provided ndarrays...
165
+ {
166
+ const x = array( [ 1, 2, 3, 4, 5, 6 ] );
167
+ const y = array( [ 1, 1, 1, 1, 1, 1 ] );
168
+ const out = array( [ 0, 0, 0, 0, 0, 0 ] );
169
+
170
+ map2Right.assign( x, y, out, clbk ); // $ExpectType ndarray
171
+ map2Right.assign( x, y, out, clbk, {} ); // $ExpectType ndarray
172
+ }
173
+
174
+ // The compiler throws an error if the `assign` method is provided a first argument other than a collection or ndarray...
175
+ {
176
+ const y1 = [ 1, 1, 1, 1, 1, 1 ];
177
+ const out1 = [ 0, 0, 0, 0, 0, 0 ];
178
+
179
+ map2Right.assign( 5, y1, out1, clbk ); // $ExpectError
180
+ map2Right.assign( true, y1, out1, clbk ); // $ExpectError
181
+ map2Right.assign( false, y1, out1, clbk ); // $ExpectError
182
+ map2Right.assign( null, y1, out1, clbk, {} ); // $ExpectError
183
+ map2Right.assign( {}, y1, out1, clbk ); // $ExpectError
184
+
185
+ map2Right.assign( 5, y1, out1, clbk, {} ); // $ExpectError
186
+ map2Right.assign( true, y1, out1, clbk, {} ); // $ExpectError
187
+ map2Right.assign( false, y1, out1, clbk, {} ); // $ExpectError
188
+ map2Right.assign( null, y1, out1, clbk, {} ); // $ExpectError
189
+ map2Right.assign( {}, y1, out1, clbk, {} ); // $ExpectError
190
+
191
+ const y2 = array( [ 1, 1, 1, 1, 1, 1 ] );
192
+ const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
193
+
194
+ map2Right.assign( 5, y2, out2, clbk ); // $ExpectError
195
+ map2Right.assign( true, y2, out2, clbk ); // $ExpectError
196
+ map2Right.assign( false, y2, out2, clbk ); // $ExpectError
197
+ map2Right.assign( null, y2, out2, clbk, {} ); // $ExpectError
198
+ map2Right.assign( {}, y2, out2, clbk ); // $ExpectError
199
+
200
+ map2Right.assign( 5, y2, out2, clbk, {} ); // $ExpectError
201
+ map2Right.assign( true, y2, out2, clbk, {} ); // $ExpectError
202
+ map2Right.assign( false, y2, out2, clbk, {} ); // $ExpectError
203
+ map2Right.assign( null, y2, out2, clbk, {} ); // $ExpectError
204
+ map2Right.assign( {}, y2, out2, clbk, {} ); // $ExpectError
205
+ }
206
+
207
+ // The compiler throws an error if the `assign` method is provided a second argument other than a collection or ndarray...
208
+ {
209
+ const x1 = [ 1, 2, 3, 4, 5, 6 ];
210
+ const out1 = [ 0, 0, 0, 0, 0, 0 ];
211
+
212
+ map2Right.assign( x1, 5, out1, clbk ); // $ExpectError
213
+ map2Right.assign( x1, true, out1, clbk ); // $ExpectError
214
+ map2Right.assign( x1, false, out1, clbk ); // $ExpectError
215
+ map2Right.assign( x1, null, out1, clbk, {} ); // $ExpectError
216
+ map2Right.assign( x1, {}, out1, clbk ); // $ExpectError
217
+
218
+ map2Right.assign( x1, 5, out1, clbk, {} ); // $ExpectError
219
+ map2Right.assign( x1, true, out1, clbk, {} ); // $ExpectError
220
+ map2Right.assign( x1, false, out1, clbk, {} ); // $ExpectError
221
+ map2Right.assign( x1, null, out1, clbk, {} ); // $ExpectError
222
+ map2Right.assign( x1, {}, out1, clbk, {} ); // $ExpectError
223
+
224
+ const x2 = array( [ 1, 2, 3, 4, 5, 6 ] );
225
+ const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
226
+
227
+ map2Right.assign( x2, 5, out2, clbk ); // $ExpectError
228
+ map2Right.assign( x2, true, out2, clbk ); // $ExpectError
229
+ map2Right.assign( x2, false, out2, clbk ); // $ExpectError
230
+ map2Right.assign( x2, null, out2, clbk, {} ); // $ExpectError
231
+ map2Right.assign( x2, {}, out2, clbk ); // $ExpectError
232
+
233
+ map2Right.assign( x2, 5, out2, clbk, {} ); // $ExpectError
234
+ map2Right.assign( x2, true, out2, clbk, {} ); // $ExpectError
235
+ map2Right.assign( x2, false, out2, clbk, {} ); // $ExpectError
236
+ map2Right.assign( x2, null, out2, clbk, {} ); // $ExpectError
237
+ map2Right.assign( x2, {}, out2, clbk, {} ); // $ExpectError
238
+ }
239
+
240
+ // The compiler throws an error if the `assign` method is provided a third argument other than a collection or ndarray...
241
+ {
242
+ const x1 = [ 1, 2, 3, 4, 5, 6 ];
243
+ const y1 = [ 1, 1, 1, 1, 1, 1 ];
244
+
245
+ map2Right.assign( x1, y1, 5, clbk ); // $ExpectError
246
+ map2Right.assign( x1, y1, true, clbk ); // $ExpectError
247
+ map2Right.assign( x1, y1, false, clbk ); // $ExpectError
248
+ map2Right.assign( x1, y1, null, clbk, {} ); // $ExpectError
249
+ map2Right.assign( x1, y1, {}, clbk ); // $ExpectError
250
+
251
+ map2Right.assign( x1, y1, 5, clbk, {} ); // $ExpectError
252
+ map2Right.assign( x1, y1, true, clbk, {} ); // $ExpectError
253
+ map2Right.assign( x1, y1, false, clbk, {} ); // $ExpectError
254
+ map2Right.assign( x1, y1, null, clbk, {} ); // $ExpectError
255
+ map2Right.assign( x1, y1, {}, clbk, {} ); // $ExpectError
256
+
257
+ const x2 = array( [ 0, 0, 0, 0, 0, 0 ] );
258
+ const y2 = array( [ 1, 1, 1, 1, 1, 1 ] );
259
+
260
+ map2Right.assign( x2, y2, 5, clbk ); // $ExpectError
261
+ map2Right.assign( x2, y2, true, clbk ); // $ExpectError
262
+ map2Right.assign( x2, y2, false, clbk ); // $ExpectError
263
+ map2Right.assign( x2, y2, null, clbk, {} ); // $ExpectError
264
+ map2Right.assign( x2, y2, {}, clbk ); // $ExpectError
265
+
266
+ map2Right.assign( x2, y2, 5, clbk, {} ); // $ExpectError
267
+ map2Right.assign( x2, y2, true, clbk, {} ); // $ExpectError
268
+ map2Right.assign( x2, y2, false, clbk, {} ); // $ExpectError
269
+ map2Right.assign( x2, y2, null, clbk, {} ); // $ExpectError
270
+ map2Right.assign( x2, y2, {}, clbk, {} ); // $ExpectError
271
+ }
272
+
273
+ // The compiler throws an error if the `assign` method is provided a third argument other than a function with a supported signature...
274
+ {
275
+ const x1 = [ 1, 2, 3, 4, 5, 6 ];
276
+ const y1 = [ 1, 1, 1, 1, 1, 1 ];
277
+ const out1 = [ 0, 0, 0, 0, 0, 0 ];
278
+
279
+ map2Right.assign( x1, y1, out1, '5' ); // $ExpectError
280
+ map2Right.assign( x1, y1, out1, true ); // $ExpectError
281
+ map2Right.assign( x1, y1, out1, false ); // $ExpectError
282
+ map2Right.assign( x1, y1, out1, 123 ); // $ExpectError
283
+ map2Right.assign( x1, y1, out1, null ); // $ExpectError
284
+ map2Right.assign( x1, y1, out1, {} ); // $ExpectError
285
+ map2Right.assign( x1, y1, out1, [] ); // $ExpectError
286
+
287
+ map2Right.assign( x1, y1, out1, '5', {} ); // $ExpectError
288
+ map2Right.assign( x1, y1, out1, true, {} ); // $ExpectError
289
+ map2Right.assign( x1, y1, out1, false, {} ); // $ExpectError
290
+ map2Right.assign( x1, y1, out1, 123, {} ); // $ExpectError
291
+ map2Right.assign( x1, y1, out1, null, {} ); // $ExpectError
292
+ map2Right.assign( x1, y1, out1, {}, {} ); // $ExpectError
293
+ map2Right.assign( x1, y1, out1, [], {} ); // $ExpectError
294
+
295
+ map2Right.assign( x1, y1, out1, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
296
+ map2Right.assign( x1, y1, out1, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
297
+
298
+ const x2 = array( [ 1, 2, 3, 4, 5, 6 ] );
299
+ const y2 = array( [ 1, 1, 1, 1, 1, 1 ] );
300
+ const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
301
+
302
+ map2Right.assign( x2, y2, out2, '5' ); // $ExpectError
303
+ map2Right.assign( x2, y2, out2, true ); // $ExpectError
304
+ map2Right.assign( x2, y2, out2, false ); // $ExpectError
305
+ map2Right.assign( x2, y2, out2, 123 ); // $ExpectError
306
+ map2Right.assign( x2, y2, out2, null ); // $ExpectError
307
+ map2Right.assign( x2, y2, out2, {} ); // $ExpectError
308
+ map2Right.assign( x2, y2, out2, [] ); // $ExpectError
309
+
310
+ map2Right.assign( x2, y2, out2, '5', {} ); // $ExpectError
311
+ map2Right.assign( x2, y2, out2, true, {} ); // $ExpectError
312
+ map2Right.assign( x2, y2, out2, false, {} ); // $ExpectError
313
+ map2Right.assign( x2, y2, out2, 123, {} ); // $ExpectError
314
+ map2Right.assign( x2, y2, out2, null, {} ); // $ExpectError
315
+ map2Right.assign( x2, y2, out2, {}, {} ); // $ExpectError
316
+ map2Right.assign( x2, y2, out2, [], {} ); // $ExpectError
317
+
318
+ map2Right.assign( x2, y2, out2, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError
319
+ map2Right.assign( x2, y2, out2, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError
320
+ }
321
+
322
+ // The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
323
+ {
324
+ const x1 = [ 1, 2, 3, 4, 5, 6 ];
325
+ const y1 = [ 1, 1, 1, 1, 1, 1 ];
326
+ const out1 = [ 0, 0, 0, 0, 0, 0 ];
327
+
328
+ map2Right.assign(); // $ExpectError
329
+ map2Right.assign( x1 ); // $ExpectError
330
+ map2Right.assign( x1, y1 ); // $ExpectError
331
+ map2Right.assign( x1, y1, out1 ); // $ExpectError
332
+ map2Right.assign( x1, y1, out1, clbk, {}, 4 ); // $ExpectError
333
+
334
+ const x2 = array( [ 1, 2, 3, 4, 5, 6 ] );
335
+ const y2 = array( [ 1, 1, 1, 1, 1, 1 ] );
336
+ const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
337
+
338
+ map2Right.assign(); // $ExpectError
339
+ map2Right.assign( x2 ); // $ExpectError
340
+ map2Right.assign( x2, y2 ); // $ExpectError
341
+ map2Right.assign( x2, y2, out2 ); // $ExpectError
342
+ map2Right.assign( x2, y2, out2, clbk, {}, 4 ); // $ExpectError
343
+ }