Skip to content

Commit cff1be6

Browse files
committed
fix: update import path for Collection type definition and refactor to use generics
Ref: bde4671
1 parent a51eab8 commit cff1be6

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

lib/node_modules/@stdlib/strided/base/map-by2/docs/types/index.d.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,22 @@
2020

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

23-
import { ArrayLike } from '@stdlib/types/array';
24-
import { Collection } from '@stdlib/types/object';
23+
import { Collection } from '@stdlib/types/array';
2524

2625
/**
2726
* Returns accessed values.
2827
*
2928
* @returns accessed values
3029
*/
31-
type NullaryCallback = () => ArrayLike<any> | void;
30+
type NullaryCallback<T, U, V> = ( this: V ) => [ T, U ] | void;
3231

3332
/**
3433
* Returns accessed values.
3534
*
3635
* @param values - array element values
3736
* @returns accessed values
3837
*/
39-
type UnaryCallback = ( values: Array<any> ) => ArrayLike<any> | void;
38+
type UnaryCallback<X, Y, T, U, V> = ( this: V, values: [ X, Y ] ) => [ T, U ] | void;
4039

4140
/**
4241
* Returns accessed values.
@@ -45,7 +44,7 @@ type UnaryCallback = ( values: Array<any> ) => ArrayLike<any> | void;
4544
* @param idx - iteration index
4645
* @returns accessed values
4746
*/
48-
type BinaryCallback = ( values: Array<any>, idx: number ) => ArrayLike<any> | void; // tslint-disable-line max-line-length
47+
type BinaryCallback<X, Y, T, U, V> = ( this: V, values: [ X, Y ], idx: number ) => [ T, U ] | void;
4948

5049
/**
5150
* Returns accessed values.
@@ -55,7 +54,7 @@ type BinaryCallback = ( values: Array<any>, idx: number ) => ArrayLike<any> | vo
5554
* @param indices - strided indices (offset + idx*stride)
5655
* @returns accessed values
5756
*/
58-
type TernaryCallback = ( values: Array<any>, idx: number, indices: Array<number> ) => ArrayLike<any> | void; // tslint-disable-line max-line-length
57+
type TernaryCallback<X, Y, T, U, V> = ( this: V, values: [ X, Y ], idx: number, indices: [ number, number, number ] ) => [ T, U ] | void;
5958

6059
/**
6160
* Returns accessed values.
@@ -66,7 +65,7 @@ type TernaryCallback = ( values: Array<any>, idx: number, indices: Array<number>
6665
* @param arrays - input and output arrays
6766
* @returns accessed values
6867
*/
69-
type QuaternaryCallback = ( values: Array<any>, idx: number, indices: Array<number>, arrays: Array<Collection> ) => ArrayLike<any> | void; // tslint-disable-line max-line-length
68+
type QuaternaryCallback<X, Y, Z, T, U, V> = ( this: V, values: [ X, Y ], idx: number, indices: [ number, number, number ], arrays: [ Collection<X>, Collection<Y>, Collection<Z> ] ) => [ T, U ] | void;
7069

7170
/**
7271
* Returns accessed values.
@@ -77,7 +76,7 @@ type QuaternaryCallback = ( values: Array<any>, idx: number, indices: Array<numb
7776
* @param arrays - input and output arrays
7877
* @returns accessed values
7978
*/
80-
type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback | QuaternaryCallback; // tslint-disable-line max-line-length
79+
type Callback<X, Y, Z, T, U, V> = NullaryCallback<T, U, V> | UnaryCallback<X, Y, T, U, V> | BinaryCallback<X, Y, T, U, V> | TernaryCallback<X, Y, T, U, V> | QuaternaryCallback<X, Y, Z, T, U, V>;
8180

8281
/**
8382
* Callback invoked for each pair of indexed strided array elements retrieved via a callback function.
@@ -86,7 +85,7 @@ type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallba
8685
* @param v2 - strided array element
8786
* @returns result
8887
*/
89-
type Binary = ( v1: any, v2: any ) => any;
88+
type Binary<T, U, Z> = ( v1: T, v2: U ) => Z;
9089

9190
/**
9291
* Interface describing `mapBy2`.
@@ -122,7 +121,7 @@ interface Routine {
122121
* mapBy2( x.length, x, 1, y, 1, z, 1, add, accessor );
123122
* // z => [ 4.0, 0.0, 12.0, 0.0, 20.0 ]
124123
*/
125-
( N: number, x: Collection, strideX: number, y: Collection, strideY: number, z: Collection, strideZ: number, fcn: Binary, clbk: Callback, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
124+
<X = unknown, Y = unknown, Z = unknown, T = unknown, U = unknown, V = unknown>( N: number, x: Collection<X>, strideX: number, y: Collection<Y>, strideY: number, z: Collection<Z>, strideZ: number, fcn: Binary<T, U, Z>, clbk: Callback<X, Y, Z, T, U, V>, thisArg?: ThisParameterType<Callback<X, Y, Z, T, U, V>> ): Collection<Z>;
126125

127126
/**
128127
* Applies a binary function to each pair of elements retrieved from strided input arrays according to a callback function and assigns results to a strided output array using alternative indexing semantics.
@@ -157,7 +156,7 @@ interface Routine {
157156
* mapBy2.ndarray( x.length, x, 1, 0, y, 1, 0, z, 1, 0, add, accessor );
158157
* // z => [ 4.0, 0.0, 12.0, 0.0, 20.0 ]
159158
*/
160-
ndarray( N: number, x: Collection, strideX: number, offsetX: number, y: Collection, strideY: number, offsetY: number, z: Collection, strideZ: number, offsetZ: number, fcn: Binary, clbk: Callback, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
159+
ndarray<X = unknown, Y = unknown, Z = unknown, T = unknown, U = unknown, V = unknown>( N: number, x: Collection<X>, strideX: number, offsetX: number, y: Collection<Y>, strideY: number, offsetY: number, z: Collection<Z>, strideZ: number, offsetZ: number, fcn: Binary<T, U, Z>, clbk: Callback<X, Y, Z, T, U, V>, thisArg?: ThisParameterType<Callback<X, Y, Z, T, U, V>> ): Collection<Z>;
161160
}
162161

163162
/**

lib/node_modules/@stdlib/strided/base/map-by2/docs/types/test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import mapBy2 = require( './index' );
2323
*
2424
* @returns accessed values
2525
*/
26-
function accessor( values: Array<number> ): Array<number> {
26+
function accessor( values: [ number, number ] ): [ number, number ] {
2727
return values;
2828
}
2929

@@ -47,8 +47,8 @@ function binary( x: number, y: number ): number {
4747
const y = new Float64Array( 10 );
4848
const z = new Float64Array( 10 );
4949

50-
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor ); // $ExpectType Collection
51-
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor, {} ); // $ExpectType Collection
50+
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor ); // $ExpectType Collection<number>
51+
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor, {} ); // $ExpectType Collection<number>
5252
}
5353

5454
// The compiler throws an error if the function is provided a first argument which is not a number...
@@ -211,8 +211,8 @@ function binary( x: number, y: number ): number {
211211
const y = new Float64Array( 10 );
212212
const z = new Float64Array( 10 );
213213

214-
mapBy2.ndarray( x.length, x, 1, 0, y, 1, 0, z, 1, 0, binary, accessor ); // $ExpectType Collection
215-
mapBy2.ndarray( x.length, x, 1, 0, y, 1, 0, z, 1, 0, binary, accessor, {} ); // $ExpectType Collection
214+
mapBy2.ndarray( x.length, x, 1, 0, y, 1, 0, z, 1, 0, binary, accessor ); // $ExpectType Collection<number>
215+
mapBy2.ndarray( x.length, x, 1, 0, y, 1, 0, z, 1, 0, binary, accessor, {} ); // $ExpectType Collection<number>
216216
}
217217

218218
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...

0 commit comments

Comments
 (0)