@stdlib/utils-map2-right 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/docs/repl.txt DELETED
@@ -1,129 +0,0 @@
1
-
2
- {{alias}}( x, y, fcn[, thisArg] )
3
- Applies a function to elements in two input arrays while iterating from
4
- right to left and assigns the results to a new array.
5
-
6
- The applied function is provided the following arguments:
7
-
8
- - v1: element from first input array.
9
- - v2: element from second input array.
10
- - idx: element index.
11
- - x: first input array.
12
- - y: second input array.
13
-
14
- The returned output array always has a "generic" data type. For example, if
15
- provided an array-like object, the function returns a generic array. If
16
- provided an ndarray, the function returns an ndarray having a "generic" data
17
- type.
18
-
19
- Input arrays must be either both array-like objects or both ndarray-like
20
- objects.
21
-
22
- If input arrays are array-like objects, the arrays must have the same number
23
- of elements.
24
-
25
- If input arrays are ndarray-like objects, the arrays must be broadcast
26
- compatible.
27
-
28
- Parameters
29
- ----------
30
- x: ArrayLikeObject|ndarray
31
- First input array.
32
-
33
- y: ArrayLikeObject|ndarray
34
- Second input array.
35
-
36
- fcn: Function
37
- Function to apply.
38
-
39
- thisArg: any (optional)
40
- Input function context.
41
-
42
- Returns
43
- -------
44
- out: Array|ndarray
45
- Output array.
46
-
47
- Examples
48
- --------
49
- // array-like object:
50
- > var f = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 );
51
- > var x = [ 1, 2, 3, 4, 5, 6 ];
52
- > var y = [ 1, 1, 1, 1, 1, 1 ];
53
- > var out = {{alias}}( x, y, f )
54
- [ 2, 3, 4, 5, 6, 7 ]
55
-
56
- // ndarray:
57
- > x = {{alias:@stdlib/ndarray/array}}( x, { 'shape': [ 2, 3 ] } );
58
- > y = {{alias:@stdlib/ndarray/array}}( y, { 'shape': [ 2, 3 ] } );
59
- > out = {{alias}}( x, y, f );
60
- > var v = out.get( 1, 1 )
61
- 6
62
-
63
-
64
- {{alias}}.assign( x, y, out, fcn[, thisArg] )
65
- Applies a function to elements in two input arrays while iterating from
66
- right to left and assigns the results to an output array.
67
-
68
- The applied function is provided the following arguments:
69
-
70
- - v1: element from first input array.
71
- - v2: element from second input array.
72
- - idx: element index.
73
- - x: first input array.
74
- - y: second input array.
75
-
76
- Input and output arrays must be either all array-like objects or all
77
- ndarray-like objects.
78
-
79
- If input and output arrays are array-like objects, the arrays must have the
80
- same number of elements.
81
-
82
- If input and output arrays are ndarray-like objects, the arrays must be
83
- broadcast compatible.
84
-
85
- Parameters
86
- ----------
87
- x: ArrayLikeObject|ndarray
88
- First input array.
89
-
90
- y: ArrayLikeObject|ndarray
91
- Second input array.
92
-
93
- out: ArrayLikeObject|ndarray
94
- Output array.
95
-
96
- fcn: Function
97
- Function to apply.
98
-
99
- thisArg: any (optional)
100
- Input function context.
101
-
102
- Returns
103
- -------
104
- out: Array|ndarray
105
- Output array.
106
-
107
- Examples
108
- --------
109
- // array-like object:
110
- > var f = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 );
111
- > var x = [ 1, 2, 3, 4, 5, 6 ];
112
- > var y = [ 1, 1, 1, 1, 1, 1 ];
113
- > var out = [ 0, 0, 0, 0, 0, 0 ];
114
- > {{alias}}.assign( x, y, out, f );
115
- > out
116
- [ 2, 3, 4, 5, 6, 7 ]
117
-
118
- // ndarray:
119
- > var opts = { 'shape': [ 2, 3 ] };
120
- > x = {{alias:@stdlib/ndarray/array}}( x, opts );
121
- > y = {{alias:@stdlib/ndarray/array}}( y, opts );
122
- > out = {{alias:@stdlib/ndarray/array}}( [ 0, 0, 0, 0, 0, 0 ], opts );
123
- > {{alias}}.assign( x, y, out, f );
124
- > var v = out.get( 1, 1 )
125
- 6
126
-
127
- See Also
128
- --------
129
-
@@ -1,343 +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 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
- }