Skip to content

Commit e756b5b

Browse files
committed
chore: clean-up
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent fdc476c commit e756b5b

File tree

8 files changed

+245
-108
lines changed

8 files changed

+245
-108
lines changed

lib/node_modules/@stdlib/array/base/map/benchmark/benchmark.assign.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var bench = require( '@stdlib/bench' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var uniform = require( '@stdlib/random/array/uniform' );
27-
var identity = require( '@stdlib/math/base/special/identity' );
27+
var identity = require( '@stdlib/number/float64/base/identity' );
2828
var zeros = require( '@stdlib/array/base/zeros' );
2929
var pkg = require( './../package.json' ).name;
3030
var map = require( './../lib' ).assign;

lib/node_modules/@stdlib/array/base/map/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var bench = require( '@stdlib/bench' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var uniform = require( '@stdlib/random/array/uniform' );
27-
var identity = require( '@stdlib/math/base/special/identity' );
27+
var identity = require( '@stdlib/number/float64/base/identity' );
2828
var pkg = require( './../package.json' ).name;
2929
var map = require( './../lib' );
3030

lib/node_modules/@stdlib/array/base/map/docs/repl.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
- index: current array element index.
1010
- arr: the input array.
1111

12-
If provided an array-like object having a `map` method, the function
13-
defers execution to that method and assumes that the method has the
14-
following signature:
12+
If provided an array-like object having a `map` method, the function defers
13+
execution to that method and assumes that the method has the following
14+
signature:
1515

1616
x.map( fcn, thisArg )
1717

lib/node_modules/@stdlib/array/base/map/docs/types/index.d.ts

Lines changed: 103 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,51 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
23+
import { Collection, AccessorArrayLike, TypedArray } from '@stdlib/types/array';
24+
25+
/**
26+
* Input array.
27+
*/
28+
type InputArray<T> = Collection<T> | AccessorArrayLike<T>;
29+
30+
/**
31+
* Output array.
32+
*/
33+
type OutputArray<T> = Collection<T> | AccessorArrayLike<T>;
34+
35+
/**
36+
* Interface for an object having a `map` method.
37+
*/
38+
interface ObjectWithMap<T> {
39+
/**
40+
* Invokes a callback for each element in an array and assigns results to a new output array.
41+
*
42+
* @param clbk - callback to apply
43+
* @param thisArg - callback execution context
44+
* @returns output array
45+
*/
46+
map<V>( clbk: Callback<T, InputArray<T>, V, unknown>, thisArg?: unknown ): ObjectWithMap<V>;
47+
}
48+
49+
/**
50+
* An array having a `map` method.
51+
*/
52+
type ArrayWithMap<T> = InputArray<T> & ObjectWithMap<T>;
2453

2554
/**
2655
* Callback invoked for each array element.
2756
*
2857
* @returns result
2958
*/
30-
type Nullary<U, V> = ( this: V ) => U;
59+
type Nullary<V, ThisArg> = ( this: ThisArg ) => V;
3160

3261
/**
3362
* Callback invoked for each array element.
3463
*
3564
* @param value - current array element
3665
* @returns result
3766
*/
38-
type Unary<T, U, V> = ( this: V, value: T ) => U;
67+
type Unary<T, V, ThisArg> = ( this: ThisArg, value: T ) => V;
3968

4069
/**
4170
* Callback invoked for each array element.
@@ -44,7 +73,7 @@ type Unary<T, U, V> = ( this: V, value: T ) => U;
4473
* @param index - current array element index
4574
* @returns result
4675
*/
47-
type Binary<T, U, V> = ( this: V, value: T, index: number ) => U;
76+
type Binary<T, V, ThisArg> = ( this: ThisArg, value: T, index: number ) => V;
4877

4978
/**
5079
* Callback invoked for each array element.
@@ -54,7 +83,7 @@ type Binary<T, U, V> = ( this: V, value: T, index: number ) => U;
5483
* @param arr - input array
5584
* @returns result
5685
*/
57-
type Ternary<T, U, V> = ( this: V, value: T, index: number, arr: Collection<T> | AccessorArrayLike<T> ) => U;
86+
type Ternary<T, U, V, ThisArg> = ( this: ThisArg, value: T, index: number, arr: U ) => V;
5887

5988
/**
6089
* Callback invoked for each array element.
@@ -64,7 +93,7 @@ type Ternary<T, U, V> = ( this: V, value: T, index: number, arr: Collection<T> |
6493
* @param arr - input array
6594
* @returns result
6695
*/
67-
type Callback<T, U, V> = Nullary<U, V> | Unary<T, U, V> | Binary<T, U, V> | Ternary<T, U, V>;
96+
type Callback<T, U, V, ThisArg> = Nullary<V, ThisArg> | Unary<T, V, ThisArg> | Binary<T, V, ThisArg> | Ternary<T, U, V, ThisArg>;
6897

6998
/**
7099
* Interface describing the main export.
@@ -79,23 +108,51 @@ interface Routine {
79108
* @returns output array
80109
*
81110
* @example
82-
* var toAccessorArray = require( '@stdlib/array/to-accessor-array' );
83111
* var ones = require( '@stdlib/array/base/ones' );
84112
*
85113
* function scale( v ) {
86-
* return v * 10.0;
114+
* return v * 10;
87115
* }
88116
*
89117
* var x = ones( 4 );
90-
* var y = map( toAccessorArray( x ), scale );
91-
* // returns [ 10.0, 10.0, 10.0, 10.0 ]
118+
* // returns [ 0, 0, 0, 0 ]
119+
*
120+
* var y = map( x, scale );
121+
* // returns [ 10, 10, 10, 10 ]
122+
*/
123+
<T = unknown, U extends Array<T> = Array<T>, V = unknown, W extends Array<V> = Array<V>, ThisArg = unknown>( x: U, fcn: Callback<T, U, V, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, V, ThisArg>> ): W;
124+
125+
/**
126+
* Applies a callback function to elements in an input array and assigns results to elements in a new output array.
127+
*
128+
* @param x - input array object
129+
* @param fcn - callback function
130+
* @param thisArg - callback execution context
131+
* @returns output array
132+
*
133+
* @example
134+
* var ones = require( '@stdlib/array/ones' );
135+
*
136+
* function scale( v ) {
137+
* return v * 10;
138+
* }
139+
*
140+
* var x = ones( 4, 'int32' );
141+
* // returns <Int32Array>[ 0, 0, 0, 0 ]
142+
*
143+
* var y = map( x, scale );
144+
* // returns <Int32Array>[ 10, 10, 10, 10 ]
92145
*/
93-
<T = unknown, U = unknown, V = unknown>( x: AccessorArrayLike<T>, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): AccessorArrayLike<U>;
146+
<T = unknown, U extends TypedArray = TypedArray, V = unknown, ThisArg = unknown>( x: U, fcn: Callback<T, U, V, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, V, ThisArg>> ): U;
94147

95148
/**
96149
* Applies a callback function to elements in an input array and assigns results to elements in a new output array.
97150
*
98-
* @param x - input array
151+
* ## Notes
152+
*
153+
* - We assume that an input array having a `map` method returns an array of the same class, and, thus, the output array should also have a `map` method.
154+
*
155+
* @param x - input array object
99156
* @param fcn - callback function
100157
* @param thisArg - callback execution context
101158
* @returns output array
@@ -104,52 +161,55 @@ interface Routine {
104161
* var ones = require( '@stdlib/array/base/ones' );
105162
*
106163
* function scale( v ) {
107-
* return v * 10.0;
164+
* return v * 10;
108165
* }
109166
*
110167
* var x = ones( 4 );
168+
* // returns [ 0, 0, 0, 0 ]
169+
*
111170
* var y = map( x, scale );
112-
* // returns [ 10.0, 10.0, 10.0, 10.0 ]
171+
* // returns [ 10, 10, 10, 10 ]
113172
*/
114-
<T = unknown, U = unknown, V = unknown>( x: Collection<T>, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): Collection<U>;
173+
<T = unknown, U extends ArrayWithMap<T> = ArrayWithMap<T>, V = unknown, W extends ArrayWithMap<V> = ArrayWithMap<V>, ThisArg = unknown>( x: U, fcn: Callback<T, U, V, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, V, ThisArg>> ): W;
115174

116175
/**
117-
* Applies a callback function to elements in an input array and assigns results to elements in an output array.
176+
* Applies a callback function to elements in an input array and assigns results to elements in a new output array.
177+
*
178+
* ## Notes
179+
*
180+
* - When an input array does not have a `map` method, we always return a new "generic" array.
118181
*
119182
* @param x - input array object
120-
* @param y - output array object
121-
* @param stride - stride length for output array
122-
* @param offset - starting index for output array
123183
* @param fcn - callback function
124184
* @param thisArg - callback execution context
125-
* @returns output array object
185+
* @returns output array
126186
*
127187
* @example
128188
* var toAccessorArray = require( '@stdlib/array/to-accessor-array' );
129189
* var ones = require( '@stdlib/array/base/ones' );
130-
* var zeros = require( '@stdlib/array/base/zeros' );
131190
*
132191
* function scale( v ) {
133192
* return v * 10;
134193
* }
194+
*
135195
* var x = ones( 4 );
136-
* var y = zeros( x.length );
196+
* // returns [ 0, 0, 0, 0 ]
137197
*
138-
* var out = map.assign( toAccessorArray( x ), toAccessorArray( y ), 1, 0 scale );
139-
* // y => [ 10, 10, 10, 10 ]
198+
* var y = map( toAccessorArray( x ), scale );
199+
* // returns [ 10, 10, 10, 10 ]
140200
*/
141-
assign<T = unknown, U = unknown, V = unknown>( x: AccessorArrayLike<T>, y: AccessorArrayLike<U>, stride: number, offset: number, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): AccessorArrayLike<U>;
201+
<T = unknown, U extends InputArray<T> = InputArray<T>, V = unknown, ThisArg = unknown>( x: U, fcn: Callback<T, U, V, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, V, ThisArg>> ): Array<V>;
142202

143203
/**
144204
* Applies a callback function to elements in an input array and assigns results to elements in an output array.
145205
*
146-
* @param x - input array
147-
* @param y - output array
206+
* @param x - input array object
207+
* @param y - output array object
148208
* @param stride - stride length for output array
149209
* @param offset - starting index for output array
150210
* @param fcn - callback function
151211
* @param thisArg - callback execution context
152-
* @returns output array
212+
* @returns output array object
153213
*
154214
* @example
155215
* var ones = require( '@stdlib/array/base/ones' );
@@ -166,8 +226,22 @@ interface Routine {
166226
*
167227
* var bool = ( out === y );
168228
* // returns true
229+
*
230+
* @example
231+
* var toAccessorArray = require( '@stdlib/array/to-accessor-array' );
232+
* var ones = require( '@stdlib/array/base/ones' );
233+
* var zeros = require( '@stdlib/array/base/zeros' );
234+
*
235+
* function scale( v ) {
236+
* return v * 10;
237+
* }
238+
* var x = ones( 4 );
239+
* var y = zeros( x.length );
240+
*
241+
* var out = map.assign( toAccessorArray( x ), toAccessorArray( y ), 1, 0 scale );
242+
* // y => [ 10, 10, 10, 10 ]
169243
*/
170-
assign<T = unknown, U = unknown, V = unknown>( x: Collection<T>, y: Collection<U>, stride: number, offset: number, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): Collection<U>;
244+
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V = unknown, W extends OutputArray<V> = OutputArray<V>, ThisArg = unknown>( x: U, y: W, stride: number, offset: number, fcn: Callback<T, U, V, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, V, ThisArg>> ): W;
171245
}
172246

173247
/**

0 commit comments

Comments
 (0)