From f48f437cc54e7928c68ed9530b354eb23a47f547 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 22 Feb 2025 02:48:09 +0500 Subject: [PATCH 01/10] feat: add console/logEachMap --- 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: passed - 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 --- --- .../@stdlib/console/log-each-map/README.md | 183 +++++++++++ .../log-each-map/benchmark/benchmark.js | 108 ++++++ .../benchmark/benchmark.length.js | 102 ++++++ .../console/log-each-map/docs/repl.txt | 30 ++ .../log-each-map/docs/types/index.d.ts | 131 ++++++++ .../console/log-each-map/docs/types/test.ts | 54 +++ .../console/log-each-map/examples/index.js | 35 ++ .../@stdlib/console/log-each-map/lib/index.js | 47 +++ .../@stdlib/console/log-each-map/lib/main.js | 162 +++++++++ .../@stdlib/console/log-each-map/package.json | 66 ++++ .../@stdlib/console/log-each-map/test/test.js | 311 ++++++++++++++++++ 11 files changed, 1229 insertions(+) create mode 100644 lib/node_modules/@stdlib/console/log-each-map/README.md create mode 100644 lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/console/log-each-map/examples/index.js create mode 100644 lib/node_modules/@stdlib/console/log-each-map/lib/index.js create mode 100644 lib/node_modules/@stdlib/console/log-each-map/lib/main.js create mode 100644 lib/node_modules/@stdlib/console/log-each-map/package.json create mode 100644 lib/node_modules/@stdlib/console/log-each-map/test/test.js diff --git a/lib/node_modules/@stdlib/console/log-each-map/README.md b/lib/node_modules/@stdlib/console/log-each-map/README.md new file mode 100644 index 000000000000..6db63063f321 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -0,0 +1,183 @@ + + +# logEachMap + +> Insert array element values into a format string, apply a callback, and print the result. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var logEachMap = require( '@stdlib/console/log-each-map' ); +``` + +#### logEachMap( str\[, ...args], clbk\[, thisArg] ) + +Inserts array element values into a format string, applies a callback, and prints the result. + +```javascript +function add( a, b ) { + return a + b; +} + +var x = [ 1, 2, 3 ]; +var y = [ 4, 5, 6 ]; + +logEachMap( '%d + %d = %d', x, y, add ); +// e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n' +``` + +The function accepts the following arguments: + +- **str**: Format string. +- **args**: Input arrays _(optional)_. +- **clbk**: Callback function. +- **thisArg**: Callback execution context _(optional)_. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function count( x, y ) { + this.count += 1; + return x + y; +} + +var x = [ 1, 2, 3 ]; +var y = [ 4, 5, 6 ]; + +var ctx = { + 'count': 0 +}; + +logEachMap( '%d + %d = %d', x, y, count, ctx ); +// e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n' + +var v = ctx.count; +// returns 3 +``` + +If an interpolated argument is not an array-like object, the argument is broadcasted for each iteration. + +```javascript +function multiply( x, y ) { + return x * y; +} + +var x = [ 1, 2, 3 ]; +var y = 2; + +logEachMap( '%d * %d = %d', x, y, multiply ); +// e.g., => '1 * 2 = 2\n2 * 2 = 4\n3 * 2 = 6\n' +``` + +The callback function is provided the following arguments: + +- **values**: Current array elements or broadcasted values. +- **index**: Current element index. +- **arrays**: Input arrays or broadcasted arrays. + +
+ + + + + +
+ +## Notes + +- If the function is provided array-like objects of unequal lengths, the function throws an error. +- The function supports array-like objects supporting the accessor protocol (e.g., [`Complex128Array`][@stdlib/array/complex128], [`Complex64Array`][@stdlib/array/complex64], etc). + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); + +function add( x, y ) { + return x + y; +} + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var y = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); + +logEachMap( '%d + %d = %d', x, y, add ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js new file mode 100644 index 000000000000..cb36368f2f64 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var proxyquire = require( 'proxyquire' ); +var bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; + + +// FUNCTIONS // + +function clbk( x ) { + return x; +} + + +// MAIN // + +bench( pkg+'::no_collections', function benchmark( b ) { + var logEachMap; + var i; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + logEachMap( '%d -> %d', i, clbk ); + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + + function logger( str ) { + if ( typeof str !== 'string' ) { + b.fail( 'should return a string' ); + } + } +}); + +bench( pkg+'::collections:len=1', function benchmark( b ) { + var logEachMap; + var i; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + logEachMap( '%d -> %d', [ i ], clbk ); + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + + function logger( str ) { + if ( typeof str !== 'string' ) { + b.fail( 'should return a string' ); + } + } +}); + +bench( pkg+'::collections:len=2', function benchmark( b ) { + var logEachMap; + var i; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + logEachMap( '%d + %d = %d', [ i ], [ i + 1 ], sum ); + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + + function sum( x, y ) { + return x + y; + } + + function logger( str ) { + if ( typeof str !== 'string' ) { + b.fail( 'should return a string' ); + } + } +}); diff --git a/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js new file mode 100644 index 000000000000..6dd50c80c858 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var proxyquire = require( 'proxyquire' ); +var bench = require( '@stdlib/bench' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; + + +// FUNCTIONS // + +function clbk( x ) { + return x; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = zeros( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var logEachMap; + var i; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + logEachMap( '%d -> %d', x, clbk ); + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + + function logger( str ) { + if ( typeof str !== 'string' ) { + b.fail( 'should return a string' ); + } + } + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::collections:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt new file mode 100644 index 000000000000..cbbca42ae867 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt @@ -0,0 +1,30 @@ +{{alias}}( str[, ...args], clbk[, thisArg] ) + Inserts array element values into a format string, applies a callback, + and prints the result. + + If an interpolated argument is not a collection, the argument is broadcasted + for each iteration. + + Parameters + ---------- + str: string + Format string. + + args: ...Collection|any (optional) + Collections or values. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Examples + -------- + > var x = [ 1, 2, 3 ]; + > var y = [ 4, 5, 6 ]; + > function sum( x, y ) { return x + y; }; + > {{alias}}( '%d + %d = %d', x, y, sum ); + + See Also + -------- diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts new file mode 100644 index 000000000000..1ab77ba924ad --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts @@ -0,0 +1,131 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Callback function that accepts no arguments. +*/ +type NullaryCallback = () => any; + +/** +* Callback function that accepts one argument. +*/ +type UnaryCallback = ( x: any ) => any; + +/** +* Callback function that accepts two arguments. +*/ +type BinaryCallback = ( x: any, y: any ) => any; + +/** +* Callback function that accepts three arguments. +*/ +type TernaryCallback = ( x: any, y: any, z: any ) => any; + +/** +* Callback function that accepts four arguments. +*/ +type QuaternaryCallback = ( w: any, x: any, y: any, z: any ) => any; + +/** +* Callback function that accepts five arguments. +*/ +type QuinaryCallback = ( v: any, w: any, x: any, y: any, z: any ) => any; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param clbk - Callback function +* @param thisArg - Callback execution context +*/ +declare function logEachMap( str: string, clbk: NullaryCallback, thisArg?: any ): void; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param arg0 - Input array or scalar value +* @param clbk - Callback function +* @param thisArg - Callback execution context +*/ +declare function logEachMap( str: string, arg0: any, clbk: UnaryCallback, thisArg?: any ): void; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param arg0 - First input array or scalar value +* @param arg1 - Second input array or scalar value +* @param clbk - Callback function +* @param thisArg - Callback execution context +*/ +declare function logEachMap( str: string, arg0: any, arg1: any, clbk: BinaryCallback, thisArg?: any ): void; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param arg0 - First input array or scalar value +* @param arg1 - Second input array or scalar value +* @param arg2 - Third input array or scalar value +* @param clbk - Callback function +* @param thisArg - Callback execution context +*/ +declare function logEachMap( str: string, arg0: any, arg1: any, arg2: any, clbk: TernaryCallback, thisArg?: any ): void; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param arg0 - First input array or scalar value +* @param arg1 - Second input array or scalar value +* @param arg2 - Third input array or scalar value +* @param arg3 - Fourth input array or scalar value +* @param clbk - Callback function +* @param thisArg - Callback execution context +*/ +declare function logEachMap( str: string, arg0: any, arg1: any, arg2: any, arg3: any, clbk: QuaternaryCallback, thisArg?: any ): void; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param arg0 - First input array or scalar value +* @param arg1 - Second input array or scalar value +* @param arg2 - Third input array or scalar value +* @param arg3 - Fourth input array or scalar value +* @param arg4 - Fifth input array or scalar value +* @param clbk - Callback function +* @param thisArg - Callback execution context +*/ +declare function logEachMap( str: string, arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, clbk: QuinaryCallback, thisArg?: any ): void; + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param str - Format string +* @param args - Input arrays or values +*/ +declare function logEachMap( str: string, ...args: Array ): void; + + +// EXPORTS // + +export = logEachMap; diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts b/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts new file mode 100644 index 000000000000..6ab7b0ee4a14 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts @@ -0,0 +1,54 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import logEachMap = require( './index' ); + +/** +* Callback function. +* +* @param x - first value +* @param y - second value +* @returns sum +*/ +function sum( x: number, y: number ): number { + return x + y; +} + +// TESTS // + +// The function returns void... +{ + const x = [ 1, 2, 3 ]; + const y = [ 4, 5, 6 ]; + + logEachMap( '%d + %d = %d', x, y, sum ); // $ExpectType void +} + +// The compiler throws an error if the first argument is not a string... +{ + const x = [ 1, 2, 3 ]; + const y = [ 4, 5, 6 ]; + + logEachMap( 123, x, y, sum ); // $ExpectError + logEachMap( true, x, y, sum ); // $ExpectError + logEachMap( false, x, y, sum ); // $ExpectError + logEachMap( null, x, y, sum ); // $ExpectError + logEachMap( undefined, x, y, sum ); // $ExpectError + logEachMap( [], x, y, sum ); // $ExpectError + logEachMap( {}, x, y, sum ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/console/log-each-map/examples/index.js b/lib/node_modules/@stdlib/console/log-each-map/examples/index.js new file mode 100644 index 000000000000..5a8e9891ac2e --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( './../lib' ); + +function add( x, y ) { + return x + y; +} + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var y = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); + +logEachMap( '%d + %d = %d', x, y, add ); diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/index.js b/lib/node_modules/@stdlib/console/log-each-map/lib/index.js new file mode 100644 index 000000000000..a5334f977963 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Insert array element values into a format string, apply a callback, and print the result. +* +* @module @stdlib/console/log-each-map +* +* @example +* var logEachMap = require( '@stdlib/console/log-each-map' ); +* +* function add( x, y ) { +* return x + y; +* } +* +* var x = [ 1, 2, 3 ]; +* var y = [ 4, 5, 6 ]; +* +* logEachMap( '%d + %d = %d', x, y, add ); +* // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js new file mode 100644 index 000000000000..adaedff870b1 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -0,0 +1,162 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); +var slice = require( '@stdlib/array/base/slice' ); +var format = require( '@stdlib/string/format' ); +var logger = require( '@stdlib/console/log' ); + + +// MAIN // + +/** +* Inserts array element values into a format string, applies a callback, and prints the result. +* +* @param {string} str - format string +* @param {...(Collection|*)} args - collections or values +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @throws {TypeError} function must be provided at least 3 arguments +* @throws {TypeError} first argument must be a string +* @throws {TypeError} callback must be a function +* @throws {RangeError} provided collections must have the same length +* @returns {void} +* +* @example +* function add( x, y ) { +* return x + y; +* } +* +* var x = [ 1, 2, 3 ]; +* var y = [ 4, 5, 6 ]; +* +* logEachMap( '%d + %d = %d', x, y, add ); +* // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n' +*/ +function logEachMap() { + var strides; + var offsets; + var getters; + var thisArg; + var cbArgs; + var values; + var nargs; + var args; + var clbk; + var str; + var len; + var v; + var s; + var n; + var i; + var j; + + nargs = arguments.length; + if ( nargs < 3 ) { + throw new TypeError( 'invalid invocation. Must provide a format string, at least one array-like object, and a callback function.' ); + } + + str = arguments[ 0 ]; + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + } + + if ( isFunction( arguments[ nargs-1 ] ) ) { + clbk = arguments[ nargs-1 ]; + thisArg = null; + n = nargs - 2; + } else { + clbk = arguments[ nargs-2 ]; + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + } + thisArg = arguments[ nargs-1 ]; + n = nargs - 3; + } + + getters = []; + strides = []; + args = []; + for ( i = 1; i < n+1; i++ ) { + v = arguments[ i ]; + if ( isCollection( v ) ) { + getters.push( resolveGetter( v ) ); + args.push( v ); + strides.push( 1 ); + len = v.length; + i += 1; + break; + } else { + v = [ v ]; + getters.push( resolveGetter( v ) ); + args.push( v ); + strides.push( 0 ); + } + } + if ( len === void 0 ) { + len = 1; + } + for ( ; i < n+1; i++ ) { + v = arguments[ i ]; + if ( isCollection( v ) ) { + if ( v.length !== len ) { + throw new RangeError( 'invalid argument. Provided collections must have the same length.' ); + } + s = 1; + } else { + v = [ v ]; + s = 0; + } + getters.push( resolveGetter( v ) ); + args.push( v ); + strides.push( s ); + } + + values = [ str ]; + offsets = []; + for ( i = 1; i < n+2; i++ ) { + values.push( null ); + offsets.push( 0 ); + } + + for ( i = 0; i < len; i++ ) { + for ( j = 0; j < n; j++ ) { + values[ j+1 ] = getters[ j ]( args[ j ], offsets[ j ] ); + offsets[ j ] += strides[ j ]; + } + cbArgs = slice( values, 1, n+1 ); + cbArgs.push( i ); + for ( j = 0; j < args.length; j++ ) { + cbArgs.push( args[j] ); + } + values[ n+1 ] = clbk.apply( thisArg, cbArgs ); + logger( format.apply( null, values ) ); + } +} + + +// EXPORTS // + +module.exports = logEachMap; diff --git a/lib/node_modules/@stdlib/console/log-each-map/package.json b/lib/node_modules/@stdlib/console/log-each-map/package.json new file mode 100644 index 000000000000..8b542f8944e9 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/console/log-each-map", + "version": "0.0.0", + "description": "Insert array element values into a format string, apply a callback, and print the result.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "console", + "log", + "logger", + "debug", + "debugging", + "print", + "map", + "each", + "foreach", + "element", + "format", + "string" + ] +} diff --git a/lib/node_modules/@stdlib/console/log-each-map/test/test.js b/lib/node_modules/@stdlib/console/log-each-map/test/test.js new file mode 100644 index 000000000000..ada167d0a025 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/test/test.js @@ -0,0 +1,311 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var proxyquire = require( 'proxyquire' ); +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var logEachMap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logEachMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided at least 3 arguments', function test( t ) { + var values; + var i; + + values = [ + [], + [ '%d' ], + [ '%d', [1, 2, 3] ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i].length+' arguments' ); + } + t.end(); + + function badValue( args ) { + return function badValue() { + logEachMap.apply( null, args ); + }; + } +}); + +tape( 'the function throws an error if not provided a string for the first argument', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + logEachMap( value, [1, 2, 3], noop ); + }; + } +}); + +tape( 'the function throws an error if the provided callback is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + logEachMap( '%d', [1, 2, 3], value ); + }; + } +}); + +tape( 'the function throws an error if provided collections of unequal length', function test( t ) { + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + logEachMap( '%d %d', [ 1, 2, 3 ], [ 1, 2 ], noop ); + } +}); + +tape( 'the function supports array-like objects', function test( t ) { + var x; + + x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + t.doesNotThrow( foo, 'does not throw' ); + t.end(); + + function foo() { + logEachMap( '%d', x, noop ); + } +}); + +tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (one array)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + expected = [ '1 -> 2', '2 -> 4', '3 -> 6' ]; + actual = []; + + logEachMap( '%d -> %d', x, scale ); + + t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.end(); + + function scale( v ) { + return v * 2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (two arrays)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var y; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + y = [ 4, 5, 6 ]; + expected = [ '1 + 4 = 5', '2 + 5 = 7', '3 + 6 = 9' ]; + actual = []; + + logEachMap( '%d + %d = %d', x, y, sum ); + + t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.end(); + + function sum( v1, v2 ) { + return v1 + v2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (three arrays)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var y; + var z; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + y = [ 4, 5, 6 ]; + z = [ 7, 8, 9 ]; + expected = [ '1 + 4 + 7 = 12', '2 + 5 + 8 = 15', '3 + 6 + 9 = 18' ]; + actual = []; + + logEachMap( '%d + %d + %d = %d', x, y, z, sum ); + + t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.end(); + + function sum( v1, v2, v3 ) { + return v1 + v2 + v3; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function inserts array element values and broadcasted scalar values into a format string, applies a callback, and prints the result', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var z; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + z = [ 7, 8, 9 ]; + expected = [ '1 + 5 + 7 = 13', '2 + 5 + 8 = 15', '3 + 5 + 9 = 17' ]; + actual = []; + + logEachMap( '%d + %d + %d = %d', x, 5, z, sum ); + + t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.end(); + + function sum( v1, v2, v3 ) { + return v1 + v2 + v3; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function inserts broadcasted scalar values into a format string, applies a callback, and prints the result', function test( t ) { + var logEachMap; + var expected; + var actual; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + expected = [ '3 + 4 = 7' ]; + actual = []; + + logEachMap( '%d + %d = %d', 3, 4, sum ); + + t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.end(); + + function sum( v1, v2 ) { + return v1 + v2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function supports providing a callback execution context', function test( t ) { + var logEachMap; + var expected; + var actual; + var ctx; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + ctx = { + 'factor': 2 + }; + expected = [ '1 -> 2', '2 -> 4', '3 -> 6' ]; + actual = []; + + logEachMap( '%d -> %d', [ 1, 2, 3 ], scale, ctx ); + + t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.end(); + + function scale( v ) { + return v * this.factor; // eslint-disable-line no-invalid-this + } + + function logger( str ) { + actual.push( str ); + } +}); From f561a3e46362fe1bbcf2aa4c83ab52c5a28be687 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 22 Feb 2025 09:14:58 +0000 Subject: [PATCH 02/10] refactor: apply suggestions from code review --- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/console/log-each-map/lib/main.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js index adaedff870b1..b4a1f63c0f18 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -24,7 +24,6 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isFunction = require( '@stdlib/assert/is-function' ); var isCollection = require( '@stdlib/assert/is-collection' ); var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); -var slice = require( '@stdlib/array/base/slice' ); var format = require( '@stdlib/string/format' ); var logger = require( '@stdlib/console/log' ); @@ -141,17 +140,16 @@ function logEachMap() { offsets.push( 0 ); } + cbArgs = []; + cbArgs[ n + 1 ] = args; for ( i = 0; i < len; i++ ) { for ( j = 0; j < n; j++ ) { - values[ j+1 ] = getters[ j ]( args[ j ], offsets[ j ] ); + cbArgs[ j ] = getters[ j ]( args[ j ], offsets[ j ] ); + values[ j + 1 ] = cbArgs[ j ]; offsets[ j ] += strides[ j ]; } - cbArgs = slice( values, 1, n+1 ); - cbArgs.push( i ); - for ( j = 0; j < args.length; j++ ) { - cbArgs.push( args[j] ); - } - values[ n+1 ] = clbk.apply( thisArg, cbArgs ); + cbArgs[ n ] = i; + values[ n + 1 ] = clbk.apply( thisArg, cbArgs ); logger( format.apply( null, values ) ); } } From 93572532ab352947c44ea3307cbfca3a3f963337 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:53:02 +0000 Subject: [PATCH 03/10] refactor: apply suggestions from code review --- 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: 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: na - 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: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/console/log-each-map/README.md | 14 +- .../console/log-each-map/docs/repl.txt | 1 + .../log-each-map/docs/types/index.d.ts | 120 ++++++++++-------- .../@stdlib/console/log-each-map/lib/main.js | 3 +- 4 files changed, 77 insertions(+), 61 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/README.md b/lib/node_modules/@stdlib/console/log-each-map/README.md index 6db63063f321..3222074e4746 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/README.md +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -58,10 +58,10 @@ logEachMap( '%d + %d = %d', x, y, add ); The function accepts the following arguments: -- **str**: Format string. -- **args**: Input arrays _(optional)_. -- **clbk**: Callback function. -- **thisArg**: Callback execution context _(optional)_. +- **str**: format string. +- **args**: input arrays _(optional)_. +- **clbk**: callback function. +- **thisArg**: callback execution context _(optional)_. To set the callback execution context, provide a `thisArg`. @@ -103,9 +103,9 @@ logEachMap( '%d * %d = %d', x, y, multiply ); The callback function is provided the following arguments: -- **values**: Current array elements or broadcasted values. -- **index**: Current element index. -- **arrays**: Input arrays or broadcasted arrays. +- **values**: current array elements or broadcasted values. +- **index**: current element index. +- **arrays**: input arrays or broadcasted arrays. diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt index cbbca42ae867..215bc9ac3e02 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt @@ -1,3 +1,4 @@ + {{alias}}( str[, ...args], clbk[, thisArg] ) Inserts array element values into a format string, applies a callback, and prints the result. diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts index 1ab77ba924ad..4c92f23b362e 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts @@ -18,110 +18,124 @@ // TypeScript Version: 4.1 +import { Array2D } from '@stdlib/types/array'; + /** * Callback function that accepts no arguments. +* +* @returns result */ -type NullaryCallback = () => any; +type NullaryCallback = ( this: U ) => any; /** * Callback function that accepts one argument. +* +* @param value - current array elements or broadcasted values +* @returns result */ -type UnaryCallback = ( x: any ) => any; +type UnaryCallback = ( this: U, x: unknown ) => any; /** * Callback function that accepts two arguments. +* +* @param firstValue - first array element or broadcasted value +* @param secondValue - second array element or broadcasted value +* @returns result */ -type BinaryCallback = ( x: any, y: any ) => any; +type BinaryCallback = ( this: U, x: unknown, y: unknown ) => any; /** -* Callback function that accepts three arguments. +* Callback function that accepts three arguments +* +* @param firstValue - first array element or broadcasted value +* @param secondValue - second array element or broadcasted value +* @param thirdValue - third array element or broadcasted value +* @returns result */ -type TernaryCallback = ( x: any, y: any, z: any ) => any; +type TernaryCallback = ( this: U, x: unknown, y: unknown, z: unknown ) => any; /** * Callback function that accepts four arguments. +* +* @param firstValue - first array element or broadcasted value +* @param secondValue - second array element or broadcasted value +* @param thirdValue - third array element or broadcasted value +* @param index - current array element index +* @returns result */ -type QuaternaryCallback = ( w: any, x: any, y: any, z: any ) => any; +type QuaternaryCallback = ( this: U, x: unknown, y: unknown, z: unknown, index: number ) => any; /** * Callback function that accepts five arguments. -*/ -type QuinaryCallback = ( v: any, w: any, x: any, y: any, z: any ) => any; - -/** -* Inserts array element values into a format string, applies a callback, and prints the result. * -* @param str - Format string -* @param clbk - Callback function -* @param thisArg - Callback execution context +* @param firstValue - first array element or broadcasted value +* @param secondValue - second array element or broadcasted value +* @param thirdValue - third array element or broadcasted value +* @param index - current array element index +* @param arrays - input arrays or broadcasted arrays +* @returns result */ -declare function logEachMap( str: string, clbk: NullaryCallback, thisArg?: any ): void; +type QuinaryCallback = ( this: U, x: unknown, y: unknown, z: unknown, index: number, arrays: Array2D ) => any; /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Callback invoked for each value. * -* @param str - Format string -* @param arg0 - Input array or scalar value -* @param clbk - Callback function -* @param thisArg - Callback execution context +* @param firstValue - first array element or broadcasted value +* @param secondValue - second array element or broadcasted value +* @param thirdValue - third array element or broadcasted value +* @param index - current array element index +* @param arrays - input arrays or broadcasted arrays +* @returns result */ -declare function logEachMap( str: string, arg0: any, clbk: UnaryCallback, thisArg?: any ): void; +type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback | QuaternaryCallback | QuinaryCallback; /** * Inserts array element values into a format string, applies a callback, and prints the result. * -* @param str - Format string -* @param arg0 - First input array or scalar value -* @param arg1 - Second input array or scalar value -* @param clbk - Callback function -* @param thisArg - Callback execution context +* @param str - format string +* @param clbk - callback function +* @param thisArg - callback execution context */ -declare function logEachMap( str: string, arg0: any, arg1: any, clbk: BinaryCallback, thisArg?: any ): void; +declare function logEachMap( str: string, clbk: Callback, thisArg?: any ): void; /** * Inserts array element values into a format string, applies a callback, and prints the result. * -* @param str - Format string -* @param arg0 - First input array or scalar value -* @param arg1 - Second input array or scalar value -* @param arg2 - Third input array or scalar value -* @param clbk - Callback function -* @param thisArg - Callback execution context +* @param str - format string +* @param arg0 - input array or scalar value +* @param clbk - callback function +* @param thisArg - callback execution context */ -declare function logEachMap( str: string, arg0: any, arg1: any, arg2: any, clbk: TernaryCallback, thisArg?: any ): void; +declare function logEachMap( str: string, arg0: unknown, clbk: Callback, thisArg?: any ): void; /** * Inserts array element values into a format string, applies a callback, and prints the result. * -* @param str - Format string -* @param arg0 - First input array or scalar value -* @param arg1 - Second input array or scalar value -* @param arg2 - Third input array or scalar value -* @param arg3 - Fourth input array or scalar value -* @param clbk - Callback function -* @param thisArg - Callback execution context +* @param str - format string +* @param arg0 - first input array or scalar value +* @param arg1 - second input array or scalar value +* @param clbk - callback function +* @param thisArg - callback execution context */ -declare function logEachMap( str: string, arg0: any, arg1: any, arg2: any, arg3: any, clbk: QuaternaryCallback, thisArg?: any ): void; +declare function logEachMap( str: string, arg0: unknown, arg1: unknown, clbk: Callback, thisArg?: any ): void; /** * Inserts array element values into a format string, applies a callback, and prints the result. * -* @param str - Format string -* @param arg0 - First input array or scalar value -* @param arg1 - Second input array or scalar value -* @param arg2 - Third input array or scalar value -* @param arg3 - Fourth input array or scalar value -* @param arg4 - Fifth input array or scalar value -* @param clbk - Callback function -* @param thisArg - Callback execution context +* @param str - format string +* @param arg0 - first input array or scalar value +* @param arg1 - second input array or scalar value +* @param arg2 - third input array or scalar value +* @param clbk - callback function +* @param thisArg - callback execution context */ -declare function logEachMap( str: string, arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, clbk: QuinaryCallback, thisArg?: any ): void; +declare function logEachMap( str: string, arg0: unknown, arg1: unknown, arg2: unknown, clbk: Callback, thisArg?: any ): void; /** * Inserts array element values into a format string, applies a callback, and prints the result. * -* @param str - Format string -* @param args - Input arrays or values +* @param str - format string +* @param args - input arrays or values */ declare function logEachMap( str: string, ...args: Array ): void; diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js index b4a1f63c0f18..ab944ea71dce 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -24,6 +24,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isFunction = require( '@stdlib/assert/is-function' ); var isCollection = require( '@stdlib/assert/is-collection' ); var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); +var nulls = require( '@stdlib/array/base/nulls' ); var format = require( '@stdlib/string/format' ); var logger = require( '@stdlib/console/log' ); @@ -140,7 +141,7 @@ function logEachMap() { offsets.push( 0 ); } - cbArgs = []; + cbArgs = nulls( n + 2 ); cbArgs[ n + 1 ] = args; for ( i = 0; i < len; i++ ) { for ( j = 0; j < n; j++ ) { From 92f1648817a13d11384bccfd69363c46f545af64 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 23 Feb 2025 05:38:16 +0000 Subject: [PATCH 04/10] docs: apply suggestion from code review --- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt index 215bc9ac3e02..fd26f7f17ccb 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt @@ -24,8 +24,8 @@ -------- > var x = [ 1, 2, 3 ]; > var y = [ 4, 5, 6 ]; - > function sum( x, y ) { return x + y; }; - > {{alias}}( '%d + %d = %d', x, y, sum ); + > function f( x, y ) { return x + y; }; + > {{alias}}( '%d + %d = %d', x, y, f ); See Also -------- From c4cfdca5207ea6789d59757d37ba3dea16ef4afb Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 15 Mar 2025 04:05:41 -0700 Subject: [PATCH 05/10] style: reduce whitespace noise Signed-off-by: Athan --- lib/node_modules/@stdlib/console/log-each-map/lib/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js index ab944ea71dce..421a9f07eb6c 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -142,15 +142,15 @@ function logEachMap() { } cbArgs = nulls( n + 2 ); - cbArgs[ n + 1 ] = args; + cbArgs[ n+1 ] = args; for ( i = 0; i < len; i++ ) { for ( j = 0; j < n; j++ ) { cbArgs[ j ] = getters[ j ]( args[ j ], offsets[ j ] ); - values[ j + 1 ] = cbArgs[ j ]; + values[ j+1 ] = cbArgs[ j ]; offsets[ j ] += strides[ j ]; } cbArgs[ n ] = i; - values[ n + 1 ] = clbk.apply( thisArg, cbArgs ); + values[ n+1 ] = clbk.apply( thisArg, cbArgs ); logger( format.apply( null, values ) ); } } From 9fa4c860ccd3f38994ecf9b1cfee4777afc4f135 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 16 Mar 2025 19:10:46 -0700 Subject: [PATCH 06/10] 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: 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: 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 --- --- .../@stdlib/console/log-each-map/README.md | 10 +- .../log-each-map/benchmark/benchmark.js | 7 + .../benchmark/benchmark.length.js | 7 + .../console/log-each-map/docs/repl.txt | 6 +- .../log-each-map/docs/types/index.d.ts | 552 ++++++++++++++++-- .../console/log-each-map/docs/types/test.ts | 115 +++- .../@stdlib/console/log-each-map/lib/index.js | 2 +- .../@stdlib/console/log-each-map/lib/main.js | 73 +-- .../@stdlib/console/log-each-map/package.json | 3 +- .../@stdlib/console/log-each-map/test/test.js | 13 - 10 files changed, 671 insertions(+), 117 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/README.md b/lib/node_modules/@stdlib/console/log-each-map/README.md index 3222074e4746..e5f67c08d94f 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/README.md +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -20,7 +20,7 @@ limitations under the License. # logEachMap -> Insert array element values into a format string, apply a callback, and print the result. +> Apply a function to array elements and print an interpolated format string. @@ -42,7 +42,7 @@ var logEachMap = require( '@stdlib/console/log-each-map' ); #### logEachMap( str\[, ...args], clbk\[, thisArg] ) -Inserts array element values into a format string, applies a callback, and prints the result. +Applies a function to array elements and prints an interpolated format string. ```javascript function add( a, b ) { @@ -103,10 +103,14 @@ logEachMap( '%d * %d = %d', x, y, multiply ); The callback function is provided the following arguments: -- **values**: current array elements or broadcasted values. +- **arg0**: current array element for the first broadcasted array. +- **arg1**: current array element for the second broadcasted array. +- **...argN**: current array element for the nth broadcasted arrays. - **index**: current element index. - **arrays**: input arrays or broadcasted arrays. +The number of `argX` arguments is determined according to the number of provided `args` arguments. If no `args` are provided, the callback is invoked without any arguments. + diff --git a/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js index cb36368f2f64..528498ba1272 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js @@ -27,6 +27,13 @@ var pkg = require( './../package.json' ).name; // FUNCTIONS // +/** +* Identity function. +* +* @private +* @param {*} x - input value +* @returns {*} input value +*/ function clbk( x ) { return x; } diff --git a/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js index 6dd50c80c858..b78b6a457ae1 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js +++ b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js @@ -29,6 +29,13 @@ var pkg = require( './../package.json' ).name; // FUNCTIONS // +/** +* Identity function. +* +* @private +* @param {*} x - input value +* @returns {*} input value +*/ function clbk( x ) { return x; } diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt index fd26f7f17ccb..2ebdd8f801ce 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( str[, ...args], clbk[, thisArg] ) - Inserts array element values into a format string, applies a callback, - and prints the result. + Applies a function to array elements and prints an interpolated format + string. If an interpolated argument is not a collection, the argument is broadcasted for each iteration. @@ -11,7 +11,7 @@ str: string Format string. - args: ...Collection|any (optional) + args: ...any (optional) Collections or values. clbk: Function diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts index 4c92f23b362e..ee0ddb447895 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts @@ -18,126 +18,580 @@ // TypeScript Version: 4.1 -import { Array2D } from '@stdlib/types/array'; +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; /** -* Callback function that accepts no arguments. +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Nullary callback. +* +* @returns result +*/ +type NullaryCallback = ( this: ThisArg ) => any; + +/** +* Unary callback. +* +* @param x - current array element +* @returns result +*/ +type UnaryFcn = ( this: ThisArg, x: T ) => any; + +/** +* Unary callback. * +* @param x - current array element +* @param index - current array element index +* @param arrays - input arrays * @returns result */ -type NullaryCallback = ( this: U ) => any; +type UnaryArgsFcn = ( this: ThisArg, x: T, index: number, arrays?: [ U ] ) => any; /** -* Callback function that accepts one argument. +* Unary callback. * -* @param value - current array elements or broadcasted values +* @param x - current array element +* @param index - current array element index +* @param arrays - input arrays * @returns result */ -type UnaryCallback = ( this: U, x: unknown ) => any; +type UnaryCallback = UnaryFcn | UnaryArgsFcn; /** -* Callback function that accepts two arguments. +* Binary callback. * -* @param firstValue - first array element or broadcasted value -* @param secondValue - second array element or broadcasted value +* @param x - current first array element +* @param y - current second array element * @returns result */ -type BinaryCallback = ( this: U, x: unknown, y: unknown ) => any; +type BinaryFcn = ( this: ThisArg, x: T, y: V ) => any; /** -* Callback function that accepts three arguments +* Binary callback. * -* @param firstValue - first array element or broadcasted value -* @param secondValue - second array element or broadcasted value -* @param thirdValue - third array element or broadcasted value +* @param x - current first array element +* @param y - current second array element +* @param index - current array element index +* @param arrays - input arrays * @returns result */ -type TernaryCallback = ( this: U, x: unknown, y: unknown, z: unknown ) => any; +type BinaryArgsFcn = ( this: ThisArg, x: T, y: V, index: number, arrays?: [ U, W ] ) => any; /** -* Callback function that accepts four arguments. +* Binary callback. * -* @param firstValue - first array element or broadcasted value -* @param secondValue - second array element or broadcasted value -* @param thirdValue - third array element or broadcasted value +* @param x - current first array element +* @param y - current second array element * @param index - current array element index +* @param arrays - input arrays * @returns result */ -type QuaternaryCallback = ( this: U, x: unknown, y: unknown, z: unknown, index: number ) => any; +type BinaryCallback = BinaryFcn | BinaryArgsFcn; /** -* Callback function that accepts five arguments. +* Ternary callback. * -* @param firstValue - first array element or broadcasted value -* @param secondValue - second array element or broadcasted value -* @param thirdValue - third array element or broadcasted value +* @param x - current first array element +* @param y - current second array element +* @param z - current third array element +* @returns result +*/ +type TernaryFcn = ( this: ThisArg, x: T, y: V, z: X ) => any; + +/** +* Ternary callback. +* +* @param x - current first array element +* @param y - current second array element +* @param z - current third array element * @param index - current array element index -* @param arrays - input arrays or broadcasted arrays +* @param arrays - input arrays * @returns result */ -type QuinaryCallback = ( this: U, x: unknown, y: unknown, z: unknown, index: number, arrays: Array2D ) => any; +type TernaryArgsFcn = ( this: ThisArg, x: T, y: V, z: X, index: number, arrays?: [ U, W, Y ] ) => any; /** -* Callback invoked for each value. +* Ternary callback. * -* @param firstValue - first array element or broadcasted value -* @param secondValue - second array element or broadcasted value -* @param thirdValue - third array element or broadcasted value +* @param x - current first array element +* @param y - current second array element +* @param z - current third array element * @param index - current array element index -* @param arrays - input arrays or broadcasted arrays +* @param arrays - input arrays * @returns result */ -type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback | QuaternaryCallback | QuinaryCallback; +type TernaryCallback = TernaryFcn | TernaryArgsFcn; + +/** +* Callback. +* +* @param args - callback arguments +* @returns results +*/ +type Callback = ( this: ThisArg, ...args: Array ) => any; + +/** +* Applies a function, inserts results into a format string, and prints the result. +* +* @param str - format string +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk() { +* return 'beep'; +* } +* +* logEachMap( '%s', clbk ); +* // e.g., => 'beep\n' +*/ +declare function logEachMap( str: string, clbk: NullaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* @param str - format string +* @param arg0 - input array +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( v ) { +* return v * 2; +* } +* +* var x = [ 1, 2, 3 ]; +* +* logEachMap( '%d', x, clbk ); +* // e.g., => '2\n4\n6\n' +*/ +declare function logEachMap = InputArray, ThisArg = unknown>( str: string, arg0: U, clbk: UnaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - input value +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( v ) { +* return v * 2; +* } +* +* logEachMap( '%d', 1, clbk ); +* // e.g., => '2\n' +*/ +declare function logEachMap( str: string, arg0: T, clbk: UnaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* @param str - format string +* @param arg0 - first input array +* @param arg1 - second input array +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y ) { +* return x + y; +* } +* +* var x = [ 1, 2, 3 ]; +* var y = [ 4, 5, 6 ]; +* +* logEachMap( '%d', x, y, clbk ); +* // e.g., => '5\n7\n9\n' +*/ +declare function logEachMap< + T = unknown, + U extends InputArray = InputArray, + V = unknown, + W extends InputArray = InputArray, + ThisArg = unknown +>( str: string, arg0: U, arg1: W, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input value +* @param arg1 - second input array +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y ) { +* return x + y; +* } +* +* var y = [ 4, 5, 6 ]; +* +* logEachMap( '%d', 1, y, clbk ); +* // e.g., => '5\n6\n7\n' +*/ +declare function logEachMap< + T = unknown, + V = unknown, + W extends InputArray = InputArray, + ThisArg = unknown +>( str: string, arg0: T, arg1: W, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input array +* @param arg1 - second input value +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y ) { +* return x + y; +* } +* +* var x = [ 1, 2, 3 ]; +* +* logEachMap( '%d', x, 1, clbk ); +* // e.g., => '2\n3\n4\n' +*/ +declare function logEachMap< + T = unknown, + U extends InputArray = InputArray, + V = unknown, + ThisArg = unknown +>( str: string, arg0: T, arg1: V, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. * * @param str - format string +* @param arg0 - first input value +* @param arg1 - second input value * @param clbk - callback function * @param thisArg - callback execution context +* +* @example +* function clbk( x, y ) { +* return x + y; +* } +* +* logEachMap( '%d', 1, 2, clbk ); +* // e.g., => '3\n' */ -declare function logEachMap( str: string, clbk: Callback, thisArg?: any ): void; +declare function logEachMap< + T = unknown, + V = unknown, + ThisArg = unknown +>( str: string, arg0: T, arg1: V, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Applies a function to array elements and prints an interpolated format string. * * @param str - format string -* @param arg0 - input array or scalar value +* @param arg0 - first input array +* @param arg1 - second input array +* @param arg2 - third input array * @param clbk - callback function * @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var x = [ 1, 2, 3 ]; +* var y = [ 4, 5, 6 ]; +* var z = [ 7, 8, 9 ]; +* +* logEachMap( '%d', x, y, z, clbk ); +* // e.g., => '12\n15\n18\n' */ -declare function logEachMap( str: string, arg0: unknown, clbk: Callback, thisArg?: any ): void; +declare function logEachMap< + T = unknown, + U extends InputArray = InputArray, + V = unknown, + W extends InputArray = InputArray, + X = unknown, + Y extends InputArray = InputArray, + ThisArg = unknown +>( str: string, arg0: U, arg1: W, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. * * @param str - format string -* @param arg0 - first input array or scalar value -* @param arg1 - second input array or scalar value +* @param arg0 - first input value +* @param arg1 - second input array +* @param arg2 - third input array * @param clbk - callback function * @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var y = [ 4, 5, 6 ]; +* var z = [ 7, 8, 9 ]; +* +* logEachMap( '%d', 1, y, z, clbk ); +* // e.g., => '12\n14\n16\n' */ -declare function logEachMap( str: string, arg0: unknown, arg1: unknown, clbk: Callback, thisArg?: any ): void; +declare function logEachMap< + T = unknown, + V = unknown, + W extends InputArray = InputArray, + X = unknown, + Y extends InputArray = InputArray, + ThisArg = unknown +>( str: string, arg0: T, arg1: W, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. * * @param str - format string -* @param arg0 - first input array or scalar value -* @param arg1 - second input array or scalar value -* @param arg2 - third input array or scalar value +* @param arg0 - first input array +* @param arg1 - second input value +* @param arg2 - third input array * @param clbk - callback function * @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var x = [ 1, 2, 3 ]; +* var z = [ 7, 8, 9 ]; +* +* logEachMap( '%d', x, 1, z, clbk ); +* // e.g., => '9\n11\n13\n' */ -declare function logEachMap( str: string, arg0: unknown, arg1: unknown, arg2: unknown, clbk: Callback, thisArg?: any ): void; +declare function logEachMap< + T = unknown, + U extends InputArray = InputArray, + V = unknown, + X = unknown, + Y extends InputArray = InputArray, + ThisArg = unknown +>( str: string, arg0: U, arg1: V, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. * * @param str - format string -* @param args - input arrays or values +* @param arg0 - first input array +* @param arg1 - second input array +* @param arg2 - third input value +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var x = [ 1, 2, 3 ]; +* var y = [ 4, 5, 6 ]; +* +* logEachMap( '%d', x, y, 1, clbk ); +* // e.g., => '6\n8\n10\n' +*/ +declare function logEachMap< + T = unknown, + U extends InputArray = InputArray, + V = unknown, + W extends InputArray = InputArray, + X = unknown, + ThisArg = unknown +>( str: string, arg0: U, arg1: W, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input value +* @param arg1 - second input value +* @param arg2 - third input array +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var z = [ 7, 8, 9 ]; +* +* logEachMap( '%d', 1, 2, z, clbk ); +* // e.g., => '10\n11\n12\n' +*/ +declare function logEachMap< + T = unknown, + V = unknown, + X = unknown, + Y extends InputArray = InputArray, + ThisArg = unknown +>( str: string, arg0: T, arg1: V, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input value +* @param arg1 - second input value +* @param arg2 - third input array +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var y = [ 4, 5, 6 ]; +* +* logEachMap( '%d', 1, y, 2, clbk ); +* // e.g., => '7\n8\n9\n' +*/ +declare function logEachMap< + T = unknown, + V = unknown, + W extends InputArray = InputArray, + X = unknown, + ThisArg = unknown +>( str: string, arg0: T, arg1: W, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input array +* @param arg1 - second input value +* @param arg2 - third input value +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var x = [ 1, 2, 3 ]; +* +* logEachMap( '%d', x, 1, 2, clbk ); +* // e.g., => '4\n5\n6\n' +*/ +declare function logEachMap< + T = unknown, + U extends InputArray = InputArray, + V = unknown, + X = unknown, + ThisArg = unknown +>( str: string, arg0: U, arg1: V, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input value +* @param arg1 - second input value +* @param arg2 - third input value +* @param clbk - callback function +* @param thisArg - callback execution context +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* logEachMap( '%d', 1, 2, 3, clbk ); +* // e.g., => '6\n' +*/ +declare function logEachMap< + T = unknown, + V = unknown, + X = unknown, + ThisArg = unknown +>( str: string, arg0: T, arg1: V, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* Applies a function to array elements and prints an interpolated format string. +* +* ## Notes +* +* - If an interpolated argument is not a collection, the argument is broadcasted for each iteration. +* +* @param str - format string +* @param arg0 - first input value +* @param arg1 - second input value +* @param arg2 - third input value +* @param args - additional input values +* +* @example +* function clbk( x, y, z ) { +* return x + y + z; +* } +* +* var x = [ 1, 2, 3 ]; +* var y = [ 4, 5, 6 ]; +* var z = [ 7, 8, 9 ]; +* +* logEachMap( '%d', x, y, z, clbk ); +* // e.g., => '12\n15\n18\n' */ -declare function logEachMap( str: string, ...args: Array ): void; +declare function logEachMap( str: string, arg0: unknown, arg1: unknown, arg2: unknown, ...args: Array ): void; // EXPORTS // diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts b/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts index 6ab7b0ee4a14..94574cd2997a 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts @@ -18,37 +18,126 @@ import logEachMap = require( './index' ); +/** +* Callback function. +* +* @returns result +*/ +function nullaryFcn(): string { + return 'foo'; +} + +/** +* Callback function. +* +* @param x - first value +* @returns result +*/ +function unaryFcn( x: number ): number { + return x; +} + /** * Callback function. * * @param x - first value * @param y - second value -* @returns sum +* @returns result */ -function sum( x: number, y: number ): number { +function binaryFcn( x: number, y: number ): number { return x + y; } +/** +* Callback function. +* +* @param x - first value +* @param y - second value +* @param z - third value +* @returns result +*/ +function ternaryFcn( x: number, y: number, z: number ): number { + return x + y + z; +} + +/** +* Callback function. +* +* @param x - first value +* @param y - second value +* @param z - third value +* @param w - fourth value +* @returns result +*/ +function quaternaryFcn( x: number, y: number, z: number, w: number ): number { + return x + y + z + w; +} + + // TESTS // // The function returns void... { const x = [ 1, 2, 3 ]; - const y = [ 4, 5, 6 ]; - logEachMap( '%d + %d = %d', x, y, sum ); // $ExpectType void + logEachMap( '%s', nullaryFcn ); // $ExpectType void + + logEachMap( '%d', x, unaryFcn ); // $ExpectType void + + logEachMap( '%d + %d = %d', x, x, binaryFcn ); // $ExpectType void + logEachMap( '%d + %d = %d', x, 1, binaryFcn ); // $ExpectType void + logEachMap( '%d + %d = %d', 1, x, binaryFcn ); // $ExpectType void + logEachMap( '%d + %d = %d', 1, 1, binaryFcn ); // $ExpectType void + + logEachMap( '%d + %d + %d = %d', x, x, x, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', 1, x, x, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', x, 1, x, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', x, x, 1, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', 1, 1, x, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', 1, x, 1, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', x, 1, 1, ternaryFcn ); // $ExpectType void + logEachMap( '%d + %d + %d = %d', 1, 1, 1, ternaryFcn ); // $ExpectType void + + logEachMap( '%d + %d + %d + %d = %d', x, x, x, x, quaternaryFcn ); // $ExpectType void } // The compiler throws an error if the first argument is not a string... { const x = [ 1, 2, 3 ]; - const y = [ 4, 5, 6 ]; - - logEachMap( 123, x, y, sum ); // $ExpectError - logEachMap( true, x, y, sum ); // $ExpectError - logEachMap( false, x, y, sum ); // $ExpectError - logEachMap( null, x, y, sum ); // $ExpectError - logEachMap( undefined, x, y, sum ); // $ExpectError - logEachMap( [], x, y, sum ); // $ExpectError - logEachMap( {}, x, y, sum ); // $ExpectError + + logEachMap( 123 ); // $ExpectError + logEachMap( true ); // $ExpectError + logEachMap( false ); // $ExpectError + logEachMap( null ); // $ExpectError + logEachMap( undefined ); // $ExpectError + logEachMap( [] ); // $ExpectError + logEachMap( {} ); // $ExpectError + logEachMap( ( x: number ): number => x ); // $ExpectError + + logEachMap( 123, x, unaryFcn ); // $ExpectError + logEachMap( true, x, unaryFcn ); // $ExpectError + logEachMap( false, x, unaryFcn ); // $ExpectError + logEachMap( null, x, unaryFcn ); // $ExpectError + logEachMap( undefined, x, unaryFcn ); // $ExpectError + logEachMap( [], x, unaryFcn ); // $ExpectError + logEachMap( {}, x, unaryFcn ); // $ExpectError + logEachMap( ( x: number ): number => x, x, unaryFcn ); // $ExpectError + + logEachMap( 123, x, x, binaryFcn ); // $ExpectError + logEachMap( true, x, x, binaryFcn ); // $ExpectError + logEachMap( false, x, x, binaryFcn ); // $ExpectError + logEachMap( null, x, x, binaryFcn ); // $ExpectError + logEachMap( undefined, x, x, binaryFcn ); // $ExpectError + logEachMap( [], x, x, binaryFcn ); // $ExpectError + logEachMap( {}, x, x, binaryFcn ); // $ExpectError + logEachMap( ( x: number ): number => x, x, x, binaryFcn ); // $ExpectError + + logEachMap( 123, x, x, x, ternaryFcn ); // $ExpectError + logEachMap( true, x, x, x, ternaryFcn ); // $ExpectError + logEachMap( false, x, x, x, ternaryFcn ); // $ExpectError + logEachMap( null, x, x, x, ternaryFcn ); // $ExpectError + logEachMap( undefined, x, x, x, ternaryFcn ); // $ExpectError + logEachMap( [], x, x, x, ternaryFcn ); // $ExpectError + logEachMap( {}, x, x, x, ternaryFcn ); // $ExpectError + logEachMap( ( x: number ): number => x, x, x, x, ternaryFcn ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/index.js b/lib/node_modules/@stdlib/console/log-each-map/lib/index.js index a5334f977963..05daa6b4d9c7 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/index.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Insert array element values into a format string, apply a callback, and print the result. +* Apply a function to array elements and print an interpolated format string. * * @module @stdlib/console/log-each-map * diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js index 421a9f07eb6c..0939f05f272f 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -25,6 +25,7 @@ var isFunction = require( '@stdlib/assert/is-function' ); var isCollection = require( '@stdlib/assert/is-collection' ); var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); var nulls = require( '@stdlib/array/base/nulls' ); +var zeros = require( '@stdlib/array/base/zeros' ); var format = require( '@stdlib/string/format' ); var logger = require( '@stdlib/console/log' ); @@ -32,15 +33,14 @@ var logger = require( '@stdlib/console/log' ); // MAIN // /** -* Inserts array element values into a format string, applies a callback, and prints the result. +* Applies a function to array elements and prints an interpolated format string. * * @param {string} str - format string -* @param {...(Collection|*)} args - collections or values +* @param {...(Collection|*)} [args] - collections or values * @param {Function} clbk - callback function * @param {*} [thisArg] - callback execution context -* @throws {TypeError} function must be provided at least 3 arguments * @throws {TypeError} first argument must be a string -* @throws {TypeError} callback must be a function +* @throws {TypeError} callback argument must be a function * @throws {RangeError} provided collections must have the same length * @returns {void} * @@ -55,7 +55,7 @@ var logger = require( '@stdlib/console/log' ); * logEachMap( '%d + %d = %d', x, y, add ); * // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n' */ -function logEachMap() { +function logEachMap( str ) { var strides; var offsets; var getters; @@ -65,41 +65,34 @@ function logEachMap() { var nargs; var args; var clbk; - var str; var len; var v; var s; - var n; var i; var j; nargs = arguments.length; - if ( nargs < 3 ) { - throw new TypeError( 'invalid invocation. Must provide a format string, at least one array-like object, and a callback function.' ); - } - - str = arguments[ 0 ]; if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - - if ( isFunction( arguments[ nargs-1 ] ) ) { - clbk = arguments[ nargs-1 ]; - thisArg = null; - n = nargs - 2; + nargs -= 1; + if ( isFunction( arguments[ nargs ] ) ) { + clbk = arguments[ nargs ]; + nargs -= 1; } else { - clbk = arguments[ nargs-2 ]; + clbk = arguments[ nargs-1 ]; if ( !isFunction( clbk ) ) { throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); } - thisArg = arguments[ nargs-1 ]; - n = nargs - 3; + thisArg = arguments[ nargs ]; + nargs -= 2; } - getters = []; strides = []; args = []; - for ( i = 1; i < n+1; i++ ) { + + // Find the first argument which is a collection... + for ( i = 1; i < nargs+1; i++ ) { v = arguments[ i ]; if ( isCollection( v ) ) { getters.push( resolveGetter( v ) ); @@ -115,10 +108,12 @@ function logEachMap() { strides.push( 0 ); } } + // If weren't provided a collection argument, all arguments are "broadcasted"... if ( len === void 0 ) { len = 1; } - for ( ; i < n+1; i++ ) { + // For the remaining arguments, resolve each argument to a collection... + for ( ; i < nargs+1; i++ ) { v = arguments[ i ]; if ( isCollection( v ) ) { if ( v.length !== len ) { @@ -133,24 +128,34 @@ function logEachMap() { args.push( v ); strides.push( s ); } + // Initialize an array containing values for generating an interpolated format string: + values = nulls( nargs+2 ); // [ str, v0, v1, ..., vN, result ] + values[ 0 ] = str; - values = [ str ]; - offsets = []; - for ( i = 1; i < n+2; i++ ) { - values.push( null ); - offsets.push( 0 ); - } + // Initialize an array containing index offsets, which are "pointers" to the current set of array elements when calling the provided callback function: + offsets = zeros( nargs ); // [ o0, o1, ..., oN ] + + // Initialize an array containing arguments to be provided to the callback function: + cbArgs = nulls( nargs+2 ); // [ v0, v1, ..., vN, index, arrays ] - cbArgs = nulls( n + 2 ); - cbArgs[ n+1 ] = args; + // The last argument provided to the callback function should be the list of input arrays/broadcasted values: + cbArgs[ nargs+1 ] = args; + + // Print an interpolated format string for each set of broadcasted array values... for ( i = 0; i < len; i++ ) { - for ( j = 0; j < n; j++ ) { + // Resolve the set of broadcasted array values... + for ( j = 0; j < nargs; j++ ) { cbArgs[ j ] = getters[ j ]( args[ j ], offsets[ j ] ); values[ j+1 ] = cbArgs[ j ]; offsets[ j ] += strides[ j ]; } - cbArgs[ n ] = i; - values[ n+1 ] = clbk.apply( thisArg, cbArgs ); + // The second-to-last callback argument should be the current array element index: + cbArgs[ nargs ] = i; + + // Compute the result of passing the current set of array elements to the provided callback function: + values[ nargs+1 ] = clbk.apply( thisArg, cbArgs ); + + // Print an interpolated string: logger( format.apply( null, values ) ); } } diff --git a/lib/node_modules/@stdlib/console/log-each-map/package.json b/lib/node_modules/@stdlib/console/log-each-map/package.json index 8b542f8944e9..5bcb02355753 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/package.json +++ b/lib/node_modules/@stdlib/console/log-each-map/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/console/log-each-map", "version": "0.0.0", - "description": "Insert array element values into a format string, apply a callback, and print the result.", + "description": "Apply a function to array elements and print an interpolated format string.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -59,6 +59,7 @@ "map", "each", "foreach", + "array", "element", "format", "string" diff --git a/lib/node_modules/@stdlib/console/log-each-map/test/test.js b/lib/node_modules/@stdlib/console/log-each-map/test/test.js index ada167d0a025..444cf7d6a6ca 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/test/test.js +++ b/lib/node_modules/@stdlib/console/log-each-map/test/test.js @@ -23,7 +23,6 @@ var proxyquire = require( 'proxyquire' ); var tape = require( 'tape' ); var noop = require( '@stdlib/utils/noop' ); -var Complex128Array = require( '@stdlib/array/complex128' ); var logEachMap = require( './../lib' ); @@ -122,18 +121,6 @@ tape( 'the function throws an error if provided collections of unequal length', } }); -tape( 'the function supports array-like objects', function test( t ) { - var x; - - x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - t.doesNotThrow( foo, 'does not throw' ); - t.end(); - - function foo() { - logEachMap( '%d', x, noop ); - } -}); - tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (one array)', function test( t ) { var logEachMap; var expected; From 869ab71f1c75866cf56f4608a4cda85fe577a764 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 16 Mar 2025 22:44:01 -0700 Subject: [PATCH 07/10] test: update tests --- 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: na - task: lint_javascript_src status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/console/log-each-map/test/test.js | 403 ++++++++++++++++-- 1 file changed, 373 insertions(+), 30 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/test/test.js b/lib/node_modules/@stdlib/console/log-each-map/test/test.js index 444cf7d6a6ca..b758bf72e00e 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/test/test.js +++ b/lib/node_modules/@stdlib/console/log-each-map/test/test.js @@ -23,6 +23,7 @@ var proxyquire = require( 'proxyquire' ); var tape = require( 'tape' ); var noop = require( '@stdlib/utils/noop' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var logEachMap = require( './../lib' ); @@ -34,29 +35,35 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if not provided at least 3 arguments', function test( t ) { +tape( 'the function throws an error if not provided a string for the first argument (binary)', function test( t ) { var values; var i; values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, [], - [ '%d' ], - [ '%d', [1, 2, 3] ] + function noop() {} ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i].length+' arguments' ); + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); } t.end(); - function badValue( args ) { + function badValue( value ) { return function badValue() { - logEachMap.apply( null, args ); + logEachMap( value, noop ); }; } }); -tape( 'the function throws an error if not provided a string for the first argument', function test( t ) { +tape( 'the function throws an error if not provided a string for the first argument (n-ary)', function test( t ) { var values; var i; @@ -79,12 +86,40 @@ tape( 'the function throws an error if not provided a string for the first argum function badValue( value ) { return function badValue() { - logEachMap( value, [1, 2, 3], noop ); + logEachMap( value, [ 1, 2, 3 ], noop ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (binary)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + logEachMap( '%d', value ); }; } }); -tape( 'the function throws an error if the provided callback is not a function', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (binary, thisArg)', function test( t ) { var values; var i; @@ -107,21 +142,179 @@ tape( 'the function throws an error if the provided callback is not a function', function badValue( value ) { return function badValue() { - logEachMap( '%d', [1, 2, 3], value ); + logEachMap( '%d', value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (n-ary)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + logEachMap( '%d', [ 1, 2, 3 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (n-ary, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + logEachMap( '%d', [ 1, 2, 3 ], value, {} ); }; } }); tape( 'the function throws an error if provided collections of unequal length', function test( t ) { - t.throws( foo, Error, 'throws an error' ); + var values; + var i; + + values = [ + [ 1, 2, 3, 4, 5 ], + [ 1, 2, 3 ], + [ 4, 5 ], + [ 6 ], + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided '+values[ i ] ); + } t.end(); - function foo() { - logEachMap( '%d %d', [ 1, 2, 3 ], [ 1, 2 ], noop ); + function badValue( value ) { + return function badValue() { + logEachMap( '%d, %d', value, [ 1, 2, 3, 4 ], noop ); + }; } }); -tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (one array)', function test( t ) { +tape( 'the function prints a formatted message', function test( t ) { + var logEachMap; + var expected; + var i; + var j; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + j = 0; + expected = [ 'foo', 'foo', 'foo' ]; + + for ( i = 0; i < expected.length; i++ ) { + logEachMap( '%s', fcn ); + } + t.strictEqual( j, expected.length, 'returns expected value' ); + t.end(); + + function fcn() { + return 'foo'; + } + + function logger( str ) { + t.equal( str, expected[ j ], 'returns expected value' ); + j += 1; + } +}); + +tape( 'the function prints a formatted message when provided only a non-array element', function test( t ) { + var logEachMap; + var expected; + var i; + var j; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + j = 0; + expected = [ 'foo -> foobar', 'foo -> foobar', 'foo -> foobar' ]; + + for ( i = 0; i < expected.length; i++ ) { + logEachMap( '%s -> %s', 'foo', fcn ); + } + t.strictEqual( j, expected.length, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v + 'bar'; + } + + function logger( str ) { + t.equal( str, expected[ j ], 'returns expected value' ); + j += 1; + } +}); + +tape( 'the function prints a formatted message when provided only two non-array elements', function test( t ) { + var logEachMap; + var expected; + var i; + var j; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + j = 0; + expected = [ 'foo + bar = foobar', 'foo + bar = foobar', 'foo + bar = foobar' ]; + + for ( i = 0; i < expected.length; i++ ) { + logEachMap( '%s + %s = %s', 'foo', 'bar', fcn ); + } + t.strictEqual( j, expected.length, 'returns expected value' ); + t.end(); + + function fcn( v1, v2 ) { + return v1 + v2; + } + + function logger( str ) { + t.equal( str, expected[ j ], 'returns expected value' ); + j += 1; + } +}); + +tape( 'the function prints a formatted message for each element in an array', function test( t ) { var logEachMap; var expected; var actual; @@ -137,7 +330,7 @@ tape( 'the function inserts array element values into a format string, applies a logEachMap( '%d -> %d', x, scale ); - t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); function scale( v ) { @@ -149,7 +342,35 @@ tape( 'the function inserts array element values into a format string, applies a } }); -tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (two arrays)', function test( t ) { +tape( 'the function prints a formatted message for each element in an array (accessors)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + expected = [ '1 -> 2', '2 -> 4', '3 -> 6' ]; + actual = []; + + logEachMap( '%d -> %d', toAccessorArray( x ), scale ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function scale( v ) { + return v * 2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function repeatedly prints a formatted message (two arrays)', function test( t ) { var logEachMap; var expected; var actual; @@ -167,7 +388,7 @@ tape( 'the function inserts array element values into a format string, applies a logEachMap( '%d + %d = %d', x, y, sum ); - t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); function sum( v1, v2 ) { @@ -179,7 +400,37 @@ tape( 'the function inserts array element values into a format string, applies a } }); -tape( 'the function inserts array element values into a format string, applies a callback, and prints the result (three arrays)', function test( t ) { +tape( 'the function repeatedly prints a formatted message (two arrays, accessors)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var y; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + y = [ 4, 5, 6 ]; + expected = [ '1 + 4 = 5', '2 + 5 = 7', '3 + 6 = 9' ]; + actual = []; + + logEachMap( '%d + %d = %d', toAccessorArray( x ), toAccessorArray( y ), sum ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function sum( v1, v2 ) { + return v1 + v2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function repeatedly prints a formatted message (three arrays)', function test( t ) { var logEachMap; var expected; var actual; @@ -199,7 +450,7 @@ tape( 'the function inserts array element values into a format string, applies a logEachMap( '%d + %d + %d = %d', x, y, z, sum ); - t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); function sum( v1, v2, v3 ) { @@ -211,29 +462,61 @@ tape( 'the function inserts array element values into a format string, applies a } }); -tape( 'the function inserts array element values and broadcasted scalar values into a format string, applies a callback, and prints the result', function test( t ) { +tape( 'the function repeatedly prints a formatted message (four arrays)', function test( t ) { var logEachMap; var expected; var actual; var x; + var y; var z; + var w; logEachMap = proxyquire( './../lib/main.js', { '@stdlib/console/log': logger }); x = [ 1, 2, 3 ]; + y = [ 4, 5, 6 ]; z = [ 7, 8, 9 ]; - expected = [ '1 + 5 + 7 = 13', '2 + 5 + 8 = 15', '3 + 5 + 9 = 17' ]; + w = [ 10, 11, 12 ]; + expected = [ '1 + 4 + 7 + 10 = 22', '2 + 5 + 8 + 11 = 26', '3 + 6 + 9 + 12 = 30' ]; actual = []; - logEachMap( '%d + %d + %d = %d', x, 5, z, sum ); + logEachMap( '%d + %d + %d + %d = %d', x, y, z, w, sum ); - t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); - function sum( v1, v2, v3 ) { - return v1 + v2 + v3; + function sum( v1, v2, v3, v4 ) { + return v1 + v2 + v3 + v4; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function broadcasts non-array arguments (one array, one scalar)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + expected = [ '1 + 5 = 6', '2 + 5 = 7', '3 + 5 = 8' ]; + actual = []; + + logEachMap( '%d + %d = %d', x, 5, sum ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function sum( v1, v2 ) { + return v1 + v2; } function logger( str ) { @@ -241,21 +524,23 @@ tape( 'the function inserts array element values and broadcasted scalar values i } }); -tape( 'the function inserts broadcasted scalar values into a format string, applies a callback, and prints the result', function test( t ) { +tape( 'the function broadcasts non-array arguments (one scalar, one array)', function test( t ) { var logEachMap; var expected; var actual; + var y; logEachMap = proxyquire( './../lib/main.js', { '@stdlib/console/log': logger }); - expected = [ '3 + 4 = 7' ]; + y = [ 1, 2, 3 ]; + expected = [ '5 + 1 = 6', '5 + 2 = 7', '5 + 3 = 8' ]; actual = []; - logEachMap( '%d + %d = %d', 3, 4, sum ); + logEachMap( '%d + %d = %d', 5, y, sum ); - t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); function sum( v1, v2 ) { @@ -267,6 +552,64 @@ tape( 'the function inserts broadcasted scalar values into a format string, appl } }); +tape( 'the function broadcasts non-array arguments (two arrays, one scalar)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var y; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 1, 2, 3 ]; + y = [ 4, 5, 6 ]; + expected = [ '1 + 4 + 5 = 10', '2 + 5 + 5 = 12', '3 + 6 + 5 = 14' ]; + actual = []; + + logEachMap( '%d + %d + %d = %d', x, y, 5, sum ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function sum( v1, v2, v3 ) { + return v1 + v2 + v3; + } + + function logger( str ) { + actual.push( str ); + } +}); + +tape( 'the function broadcasts non-array arguments (two scalars, one array)', function test( t ) { + var logEachMap; + var expected; + var actual; + var z; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + z = [ 1, 2, 3 ]; + expected = [ '4 + 5 + 1 = 10', '4 + 5 + 2 = 11', '4 + 5 + 3 = 12' ]; + actual = []; + + logEachMap( '%d + %d + %d = %d', 4, 5, z, sum ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function sum( v1, v2, v3 ) { + return v1 + v2 + v3; + } + + function logger( str ) { + actual.push( str ); + } +}); + tape( 'the function supports providing a callback execution context', function test( t ) { var logEachMap; var expected; @@ -285,7 +628,7 @@ tape( 'the function supports providing a callback execution context', function t logEachMap( '%d -> %d', [ 1, 2, 3 ], scale, ctx ); - t.deepEqual( actual, expected, 'returns expected mapped values' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); function scale( v ) { From 357a1aad285772cf5ca5811bbfc6ada16373286e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 16 Mar 2025 22:48:00 -0700 Subject: [PATCH 08/10] docs: update descriptions --- 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: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/console/log-each-map/README.md | 4 +-- .../console/log-each-map/docs/repl.txt | 4 +-- .../log-each-map/docs/types/index.d.ts | 32 +++++++++---------- .../@stdlib/console/log-each-map/lib/index.js | 2 +- .../@stdlib/console/log-each-map/lib/main.js | 2 +- .../@stdlib/console/log-each-map/package.json | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/README.md b/lib/node_modules/@stdlib/console/log-each-map/README.md index e5f67c08d94f..6f20b8f53530 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/README.md +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -20,7 +20,7 @@ limitations under the License. # logEachMap -> Apply a function to array elements and print an interpolated format string. +> Insert array element values and the result of a callback function into a format string and print the result. @@ -42,7 +42,7 @@ var logEachMap = require( '@stdlib/console/log-each-map' ); #### logEachMap( str\[, ...args], clbk\[, thisArg] ) -Applies a function to array elements and prints an interpolated format string. +Inserts array element values and the result of a callback function into a format string and prints the result. ```javascript function add( a, b ) { diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt index 2ebdd8f801ce..bb81e87a2b2b 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( str[, ...args], clbk[, thisArg] ) - Applies a function to array elements and prints an interpolated format - string. + Inserts array element values and the result of a callback function into a + format string and prints the result. If an interpolated argument is not a collection, the argument is broadcasted for each iteration. diff --git a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts index ee0ddb447895..5e0196b56e40 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts @@ -134,7 +134,7 @@ type TernaryCallback = TernaryFcn | type Callback = ( this: ThisArg, ...args: Array ) => any; /** -* Applies a function, inserts results into a format string, and prints the result. +* Inserts the result of a callback function into a format string and prints the result. * * @param str - format string * @param clbk - callback function @@ -151,7 +151,7 @@ type Callback = ( this: ThisArg, ...args: Array ) => any; declare function logEachMap( str: string, clbk: NullaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * @param str - format string * @param arg0 - input array @@ -171,7 +171,7 @@ declare function logEachMap( str: string, clbk: NullaryCallba declare function logEachMap = InputArray, ThisArg = unknown>( str: string, arg0: U, clbk: UnaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -193,7 +193,7 @@ declare function logEachMap = InputArray declare function logEachMap( str: string, arg0: T, clbk: UnaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * @param str - format string * @param arg0 - first input array @@ -221,7 +221,7 @@ declare function logEachMap< >( str: string, arg0: U, arg1: W, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -251,7 +251,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: W, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -281,7 +281,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: V, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -308,7 +308,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: V, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * @param str - format string * @param arg0 - first input array @@ -340,7 +340,7 @@ declare function logEachMap< >( str: string, arg0: U, arg1: W, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -374,7 +374,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: W, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -408,7 +408,7 @@ declare function logEachMap< >( str: string, arg0: U, arg1: V, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -442,7 +442,7 @@ declare function logEachMap< >( str: string, arg0: U, arg1: W, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -474,7 +474,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: V, arg2: Y, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -506,7 +506,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: W, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -538,7 +538,7 @@ declare function logEachMap< >( str: string, arg0: U, arg1: V, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * @@ -567,7 +567,7 @@ declare function logEachMap< >( str: string, arg0: T, arg1: V, arg2: X, clbk: TernaryCallback, thisArg?: ThisParameterType> ): void; /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * ## Notes * diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/index.js b/lib/node_modules/@stdlib/console/log-each-map/lib/index.js index 05daa6b4d9c7..27e046b5d53b 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/index.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Apply a function to array elements and print an interpolated format string. +* Insert array element values and the result of a callback function into a format string and print the result. * * @module @stdlib/console/log-each-map * diff --git a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js index 0939f05f272f..37d9f4065b54 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/lib/main.js +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -33,7 +33,7 @@ var logger = require( '@stdlib/console/log' ); // MAIN // /** -* Applies a function to array elements and prints an interpolated format string. +* Inserts array element values and the result of a callback function into a format string and prints the result. * * @param {string} str - format string * @param {...(Collection|*)} [args] - collections or values diff --git a/lib/node_modules/@stdlib/console/log-each-map/package.json b/lib/node_modules/@stdlib/console/log-each-map/package.json index 5bcb02355753..f797589098d0 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/package.json +++ b/lib/node_modules/@stdlib/console/log-each-map/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/console/log-each-map", "version": "0.0.0", - "description": "Apply a function to array elements and print an interpolated format string.", + "description": "Insert array element values and the result of a callback function into a format string and print the result.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 00b32f26aeceda1c4445879ad327939366251c21 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 16 Mar 2025 22:51:17 -0700 Subject: [PATCH 09/10] docs: update description --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/console/log-each-map/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/README.md b/lib/node_modules/@stdlib/console/log-each-map/README.md index 6f20b8f53530..2b7fe995e60c 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/README.md +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -105,7 +105,7 @@ The callback function is provided the following arguments: - **arg0**: current array element for the first broadcasted array. - **arg1**: current array element for the second broadcasted array. -- **...argN**: current array element for the nth broadcasted arrays. +- **...argN**: current array element for the nth broadcasted array. - **index**: current element index. - **arrays**: input arrays or broadcasted arrays. From 88a850f4933c98dd1ce03b608b229deb69777a7e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 16 Mar 2025 22:53:20 -0700 Subject: [PATCH 10/10] docs: update description --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/console/log-each-map/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/README.md b/lib/node_modules/@stdlib/console/log-each-map/README.md index 2b7fe995e60c..877fd1c264d1 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/README.md +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -107,7 +107,7 @@ The callback function is provided the following arguments: - **arg1**: current array element for the second broadcasted array. - **...argN**: current array element for the nth broadcasted array. - **index**: current element index. -- **arrays**: input arrays or broadcasted arrays. +- **arrays**: broadcasted arrays. If an argument was broadcasted, the corresponding array is a single-element generic array containing the original element. The number of `argX` arguments is determined according to the number of provided `args` arguments. If no `args` are provided, the callback is invoked without any arguments.