Skip to content

Commit d1ff8b2

Browse files
committed
refactor: rename clbk to predicate to use more descriptive term
--- 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: passed - task: lint_package_json status: passed - 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: na - 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 2c9bdf9 commit d1ff8b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+414
-432
lines changed

lib/node_modules/@stdlib/ndarray/base/every-by/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# everyBy
2222

23-
> Test whether every element in an ndarray is truthy according to a callback function.
23+
> Test whether all elements in an ndarray pass a test implemented by a predicate function.
2424
2525
<section class="intro">
2626

@@ -36,9 +36,9 @@ limitations under the License.
3636
var everyBy = require( '@stdlib/ndarray/base/every-by' );
3737
```
3838

39-
#### everyBy( arrays, clbk\[, thisArg] )
39+
#### everyBy( arrays, predicate\[, thisArg] )
4040

41-
Tests whether every element in an ndarray is truthy according to a callback function.
41+
Tests whether all elements in an ndarray pass a test implemented by a predicate function.
4242

4343
<!-- eslint-disable max-len -->
4444

@@ -79,8 +79,8 @@ var out = everyBy( [ x ], clbk );
7979
The function accepts the following arguments:
8080

8181
- **arrays**: array-like object containing an input ndarray.
82-
- **clbk**: callback function.
83-
- **thisArg**: callback execution context (_optional_).
82+
- **predicate**: predicate function.
83+
- **thisArg**: predicate function execution context (_optional_).
8484

8585
The provided ndarray should be an `object` with the following properties:
8686

@@ -91,13 +91,13 @@ The provided ndarray should be an `object` with the following properties:
9191
- **offset**: index offset.
9292
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
9393

94-
The callback function is provided the following arguments:
94+
The predicate function is provided the following arguments:
9595

9696
- **value**: current array element.
9797
- **indices**: current array element indices.
9898
- **arr**: the input ndarray.
9999

100-
To set the callback function execution context, provide a `thisArg`.
100+
To set the predicate function execution context, provide a `thisArg`.
101101

102102
<!-- eslint-disable no-invalid-this, max-len -->
103103

@@ -152,6 +152,7 @@ var count = ctx.count;
152152
## Notes
153153

154154
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing the operation in order to achieve better performance.
155+
- If provided an empty ndarray, the function returns `true`.
155156

156157
</section>
157158

lib/node_modules/@stdlib/ndarray/base/every-by/docs/repl.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
{{alias}}( arrays, clbk[, thisArg] )
3-
Tests whether every element in an ndarray is truthy according to a callback
4-
function.
2+
{{alias}}( arrays, predicate[, thisArg] )
3+
Tests whether all elements in an ndarray pass a test implemented by a
4+
predicate function.
55

66
A provided "ndarray" should be an `object` with the following properties:
77

@@ -13,28 +13,30 @@
1313
- order: specifies whether an ndarray is row-major (C-style) or column-major
1414
(Fortran-style).
1515

16-
The callback function is provided the following arguments:
16+
The predicate function is provided the following arguments:
1717

1818
- value: current array element.
1919
- indices: current array element indices.
2020
- arr: the input ndarray.
2121

22+
If provided an empty ndarray, the function returns `true`.
23+
2224
Parameters
2325
----------
2426
arrays: ArrayLikeObject<ndarray>
2527
Array-like object containing an input ndarray.
2628

27-
clbk: Function
28-
Callback function.
29+
predicate: Function
30+
Predicate function.
2931

3032
thisArg: any (optional)
31-
Callback execution context.
33+
Predicate function execution context.
3234

3335
Returns
3436
-------
3537
out: boolean
36-
Boolean indicating whether every element in an ndarray is truthy
37-
according to a callback function.
38+
Boolean indicating whether all elements in an ndarray pass a test
39+
implemented by a predicate function.
3840

3941
Examples
4042
--------

lib/node_modules/@stdlib/ndarray/base/every-by/docs/types/index.d.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,61 @@ import { ArrayLike } from '@stdlib/types/array';
2424
import { typedndarray } from '@stdlib/types/ndarray';
2525

2626
/**
27-
* Callback invoked for each ndarray element.
27+
* Returns a boolean indicating whether an element passes a test.
28+
*
29+
* @returns boolean indicating whether an ndarray element passes a test
2830
*/
29-
type Nullary<U> = ( this: U ) => void;
31+
type Nullary<U> = ( this: U ) => boolean;
3032

3133
/**
32-
* Callback invoked for each ndarray element.
34+
* Returns a boolean indicating whether an element passes a test.
3335
*
3436
* @param value - current array element
37+
* @returns boolean indicating whether an ndarray element passes a test
3538
*/
36-
type Unary<T, U> = ( this: U, value: T ) => void;
39+
type Unary<T, U> = ( this: U, value: T ) => boolean;
3740

3841
/**
39-
* Callback invoked for each ndarray element.
42+
* Returns a boolean indicating whether an element passes a test.
4043
*
4144
* @param value - current array element
4245
* @param indices - current array element indices
46+
* @returns boolean indicating whether an ndarray element passes a test
4347
*/
44-
type Binary<T, U> = ( this: U, value: T, indices: Array<number> ) => void;
48+
type Binary<T, U> = ( this: U, value: T, indices: Array<number> ) => boolean;
4549

4650
/**
47-
* Callback invoked for each ndarray element.
51+
* Returns a boolean indicating whether an element passes a test.
4852
*
4953
* @param value - current array element
5054
* @param indices - current array element indices
5155
* @param arr - input array
56+
* @returns boolean indicating whether an ndarray element passes a test
5257
*/
53-
type Ternary<T, U> = ( this: U, value: T, indices: Array<number>, arr: typedndarray<T> ) => void;
58+
type Ternary<T, U> = ( this: U, value: T, indices: Array<number>, arr: typedndarray<T> ) => boolean;
5459

5560
/**
56-
* Callback invoked for each ndarray element.
61+
* Returns a boolean indicating whether an element passes a test.
5762
*
5863
* @param value - current array element
5964
* @param indices - current array element indices
6065
* @param arr - input array
66+
* @returns boolean indicating whether an ndarray element passes a test
6167
*/
62-
type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
68+
type Predicate<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
6369

6470
/**
65-
* Tests whether every element in an ndarray is truthy according to a callback function.
71+
* Tests whether all elements in an ndarray pass a test implemented by a predicate function.
6672
*
67-
* @param arrays - array-like object containing an output ndarray
68-
* @param clbk - callback function
69-
* @param thisArg - callback execution context
70-
* @returns result
73+
* @param arrays - array-like object containing an input ndarray
74+
* @param predicate - predicate function
75+
* @param thisArg - predicate function execution context
76+
* @returns boolean indicating whether all elements pass a test
7177
*
7278
* @example
7379
* var Float64Array = require( '@stdlib/array/float64' );
7480
*
75-
* function clbk( value ) {
81+
* function predicate( value ) {
7682
* return value > 0.0;
7783
* }
7884
*
@@ -88,14 +94,14 @@ type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
8894
* // Define the index offset:
8995
* var ox = 1;
9096
*
91-
* // Create the output ndarray:
97+
* // Create the input ndarray:
9298
* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
9399
*
94-
* // Apply the callback function:
95-
* var out = everyBy( [ x ], clbk );
100+
* // Test elements:
101+
* var out = everyBy( [ x ], predicate );
96102
* // returns true
97103
*/
98-
declare function everyBy<T = unknown, U = unknown>( arrays: ArrayLike<typedndarray<T>>, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): Boolean;
104+
declare function everyBy<T = unknown, U = unknown>( arrays: ArrayLike<typedndarray<T>>, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): boolean;
99105

100106

101107
// EXPORTS //

lib/node_modules/@stdlib/ndarray/base/every-by/docs/types/test.ts

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,29 @@
1818

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

21-
import { ndarray } from '@stdlib/types/ndarray';
21+
import zeros = require( '@stdlib/ndarray/zeros' );
2222
import everyBy = require( './index' );
2323

2424
/**
25-
* Mock function to create an ndarray-like object.
26-
*
27-
* @returns ndarray-like object
28-
*/
29-
function array(): ndarray {
30-
const obj: ndarray = {
31-
'byteLength': 80,
32-
'BYTES_PER_ELEMENT': 8,
33-
'data': new Float64Array( 10 ),
34-
'dtype': 'float64',
35-
'flags': {
36-
'ROW_MAJOR_CONTIGUOUS': true,
37-
'COLUMN_MAJOR_CONTIGUOUS': false
38-
},
39-
'length': 10,
40-
'ndims': 1,
41-
'offset': 0,
42-
'order': 'row-major',
43-
'shape': [ 10 ],
44-
'strides': [ 1 ],
45-
'get': (): number => 0,
46-
'set': (): ndarray => obj
47-
};
48-
return obj;
49-
}
50-
51-
/**
52-
* Callback function.
25+
* Predicate function.
5326
*
5427
* @param v - ndarray element
5528
* @returns result
5629
*/
57-
function clbk( v: any ): Boolean {
30+
function clbk( v: any ): boolean {
5831
return v > 0.0;
5932
}
6033

6134

6235
// TESTS //
6336

64-
// The function returns a `Boolean`...
37+
// The function returns a boolean...
6538
{
66-
const x = array();
39+
const x = zeros( [ 2, 2 ] );
6740
const arrays = [ x ];
6841

69-
everyBy( arrays, clbk ); // $ExpectType Boolean
70-
everyBy( arrays, clbk, {} ); // $ExpectType Boolean
42+
everyBy( arrays, clbk ); // $ExpectType boolean
43+
everyBy( arrays, clbk, {} ); // $ExpectType boolean
7144
}
7245

7346
// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects...
@@ -93,7 +66,7 @@ function clbk( v: any ): Boolean {
9366

9467
// The compiler throws an error if the function is provided a second argument which is not a callback function...
9568
{
96-
const x = array();
69+
const x = zeros( [ 2, 2 ] );
9770
const arrays = [ x ];
9871

9972
everyBy( arrays, '10' ); // $ExpectError
@@ -117,7 +90,7 @@ function clbk( v: any ): Boolean {
11790

11891
// The compiler throws an error if the function is provided an unsupported number of arguments...
11992
{
120-
const x = array();
93+
const x = zeros( [ 2, 2 ] );
12194
const arrays = [ x ];
12295

12396
everyBy(); // $ExpectError

lib/node_modules/@stdlib/ndarray/base/every-by/lib/0d.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MAIN //
2222

2323
/**
24-
* Tests whether every element in an ndarray is truthy according to a callback function.
24+
* Tests whether all elements in an ndarray pass a test implemented by a predicate function.
2525
*
2626
* @private
2727
* @param {Object} x - object containing ndarray meta data
@@ -32,14 +32,14 @@
3232
* @param {IntegerArray} x.strides - stride lengths
3333
* @param {NonNegativeInteger} x.offset - index offset
3434
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
35-
* @param {Function} clbk - callback function
36-
* @param {*} thisArg - callback execution context
37-
* @returns {boolean} result
35+
* @param {Function} predicate - predicate function
36+
* @param {*} thisArg - predicate function execution context
37+
* @returns {boolean} boolean indicating whether all elements pass a test
3838
*
3939
* @example
4040
* var Float64Array = require( '@stdlib/array/float64' );
4141
*
42-
* function clbk( value ) {
42+
* function predicate( value ) {
4343
* return value > 0.0;
4444
* }
4545
*
@@ -67,11 +67,11 @@
6767
* };
6868
*
6969
* // Test elements:
70-
* var out = every0d( x, clbk );
70+
* var out = every0d( x, predicate );
7171
* // returns true
7272
*/
73-
function every0d( x, clbk, thisArg ) {
74-
if ( clbk.call( thisArg, x.data[ x.offset ], [], x.ref ) ) {
73+
function every0d( x, predicate, thisArg ) {
74+
if ( predicate.call( thisArg, x.data[ x.offset ], [], x.ref ) ) {
7575
return true;
7676
}
7777
return false;

lib/node_modules/@stdlib/ndarray/base/every-by/lib/0d_accessors.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MAIN //
2222

2323
/**
24-
* Tests whether every element in an ndarray is truthy according to a callback function.
24+
* Tests whether all elements in an ndarray pass a test implemented by a predicate function.
2525
*
2626
* @private
2727
* @param {Object} x - object containing ndarray meta data
@@ -33,15 +33,15 @@
3333
* @param {NonNegativeInteger} x.offset - index offset
3434
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
3535
* @param {Array<Function>} x.accessors - data buffer accessors
36-
* @param {Function} clbk - callback function
37-
* @param {*} thisArg - callback execution context
38-
* @returns {boolean} result
36+
* @param {Function} predicate - predicate function
37+
* @param {*} thisArg - predicate function execution context
38+
* @returns {boolean} boolean indicating whether all elements pass a test
3939
*
4040
* @example
4141
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
4242
* var accessors = require( '@stdlib/array/base/accessors' );
4343
*
44-
* function clbk( value ) {
44+
* function predicate( value ) {
4545
* return value > 0.0;
4646
* }
4747
*
@@ -70,11 +70,11 @@
7070
* };
7171
*
7272
* // Test elements:
73-
* var out = every0d( x, clbk );
73+
* var out = every0d( x, predicate );
7474
* // returns true
7575
*/
76-
function every0d( x, clbk, thisArg ) {
77-
if ( clbk.call( thisArg, x.accessors[ 0 ]( x.data, x.offset ), [], x.ref ) ) { // eslint-disable-line max-len
76+
function every0d( x, predicate, thisArg ) {
77+
if ( predicate.call( thisArg, x.accessors[ 0 ]( x.data, x.offset ), [], x.ref ) ) { // eslint-disable-line max-len
7878
return true;
7979
}
8080
return false;

0 commit comments

Comments
 (0)