Skip to content

Commit

Permalink
fix: update import path for Collection type definition and refactor…
Browse files Browse the repository at this point in the history
… to use generics

Ref: bde4671
  • Loading branch information
kgryte committed Sep 20, 2023
1 parent a51eab8 commit cff1be6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions lib/node_modules/@stdlib/strided/base/map-by2/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@

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

import { ArrayLike } from '@stdlib/types/array';
import { Collection } from '@stdlib/types/object';
import { Collection } from '@stdlib/types/array';

/**
* Returns accessed values.
*
* @returns accessed values
*/
type NullaryCallback = () => ArrayLike<any> | void;
type NullaryCallback<T, U, V> = ( this: V ) => [ T, U ] | void;

/**
* Returns accessed values.
*
* @param values - array element values
* @returns accessed values
*/
type UnaryCallback = ( values: Array<any> ) => ArrayLike<any> | void;
type UnaryCallback<X, Y, T, U, V> = ( this: V, values: [ X, Y ] ) => [ T, U ] | void;

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

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

/**
* Returns accessed values.
Expand All @@ -66,7 +65,7 @@ type TernaryCallback = ( values: Array<any>, idx: number, indices: Array<number>
* @param arrays - input and output arrays
* @returns accessed values
*/
type QuaternaryCallback = ( values: Array<any>, idx: number, indices: Array<number>, arrays: Array<Collection> ) => ArrayLike<any> | void; // tslint-disable-line max-line-length
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;

/**
* Returns accessed values.
Expand All @@ -77,7 +76,7 @@ type QuaternaryCallback = ( values: Array<any>, idx: number, indices: Array<numb
* @param arrays - input and output arrays
* @returns accessed values
*/
type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback | QuaternaryCallback; // tslint-disable-line max-line-length
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>;

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

/**
* Interface describing `mapBy2`.
Expand Down Expand Up @@ -122,7 +121,7 @@ interface Routine {
* mapBy2( x.length, x, 1, y, 1, z, 1, add, accessor );
* // z => [ 4.0, 0.0, 12.0, 0.0, 20.0 ]
*/
( 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
<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>;

/**
* 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.
Expand Down Expand Up @@ -157,7 +156,7 @@ interface Routine {
* mapBy2.ndarray( x.length, x, 1, 0, y, 1, 0, z, 1, 0, add, accessor );
* // z => [ 4.0, 0.0, 12.0, 0.0, 20.0 ]
*/
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
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>;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/strided/base/map-by2/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import mapBy2 = require( './index' );
*
* @returns accessed values
*/
function accessor( values: Array<number> ): Array<number> {
function accessor( values: [ number, number ] ): [ number, number ] {
return values;
}

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

mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor ); // $ExpectType Collection
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor, {} ); // $ExpectType Collection
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor ); // $ExpectType Collection<number>
mapBy2( x.length, x, 1, y, 1, z, 1, binary, accessor, {} ); // $ExpectType Collection<number>
}

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

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

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

0 comments on commit cff1be6

Please sign in to comment.