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..877fd1c264d1 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/README.md @@ -0,0 +1,187 @@ + + +# logEachMap + +> Insert array element values and the result of a callback function into a format string and print the result. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var logEachMap = require( '@stdlib/console/log-each-map' ); +``` + +#### logEachMap( str\[, ...args], clbk\[, thisArg] ) + +Inserts array element values and the result of a callback function into a format string 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: + +- **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 array. +- **index**: current element index. +- **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. + +
+ + + + + +
+ +## 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..528498ba1272 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @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 // + +/** +* Identity function. +* +* @private +* @param {*} x - input value +* @returns {*} input value +*/ +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..b78b6a457ae1 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/benchmark/benchmark.length.js @@ -0,0 +1,109 @@ +/** +* @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 // + +/** +* Identity function. +* +* @private +* @param {*} x - input value +* @returns {*} input value +*/ +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..bb81e87a2b2b --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}( str[, ...args], clbk[, thisArg] ) + 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. + + Parameters + ---------- + str: string + Format string. + + args: ...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 f( x, y ) { return x + y; }; + > {{alias}}( '%d + %d = %d', x, y, f ); + + 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..5e0196b56e40 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/index.d.ts @@ -0,0 +1,599 @@ +/* +* @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 + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* 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 UnaryArgsFcn = ( this: ThisArg, x: T, index: number, arrays?: [ U ] ) => any; + +/** +* Unary callback. +* +* @param x - current array element +* @param index - current array element index +* @param arrays - input arrays +* @returns result +*/ +type UnaryCallback = UnaryFcn | UnaryArgsFcn; + +/** +* Binary callback. +* +* @param x - current first array element +* @param y - current second array element +* @returns result +*/ +type BinaryFcn = ( this: ThisArg, x: T, y: V ) => any; + +/** +* Binary callback. +* +* @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 BinaryArgsFcn = ( this: ThisArg, x: T, y: V, index: number, arrays?: [ U, W ] ) => any; + +/** +* Binary callback. +* +* @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 BinaryCallback = BinaryFcn | BinaryArgsFcn; + +/** +* Ternary callback. +* +* @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 +* @returns result +*/ +type TernaryArgsFcn = ( this: ThisArg, x: T, y: V, z: X, index: number, arrays?: [ U, W, Y ] ) => 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 +* @returns result +*/ +type TernaryCallback = TernaryFcn | TernaryArgsFcn; + +/** +* Callback. +* +* @param args - callback arguments +* @returns results +*/ +type Callback = ( this: ThisArg, ...args: Array ) => any; + +/** +* Inserts the result of a callback function 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; + +/** +* 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 +* @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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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; + +/** +* 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 +* @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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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 and the result of a callback function into a format string and prints the result. +* +* ## 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< + T = unknown, + V = unknown, + ThisArg = unknown +>( str: string, arg0: T, arg1: V, clbk: BinaryCallback, thisArg?: ThisParameterType> ): void; + +/** +* 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 +* @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< + 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 and the result of a callback function into a format string and prints the result. +* +* ## 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 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< + 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 and the result of a callback function into a format string and prints the result. +* +* ## 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 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< + 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 and the result of a callback function into a format string and prints the result. +* +* ## 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 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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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; + +/** +* Inserts array element values and the result of a callback function into a format string and prints the result. +* +* ## 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, arg0: unknown, arg1: unknown, arg2: unknown, ...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..94574cd2997a --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/docs/types/test.ts @@ -0,0 +1,143 @@ +/* +* @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. +* +* @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 result +*/ +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 ]; + + 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 ]; + + 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/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..27e046b5d53b --- /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 and the result of a callback function into a format string 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..37d9f4065b54 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/lib/main.js @@ -0,0 +1,166 @@ +/** +* @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 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' ); + + +// MAIN // + +/** +* 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 +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @throws {TypeError} first argument must be a string +* @throws {TypeError} callback argument 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( str ) { + var strides; + var offsets; + var getters; + var thisArg; + var cbArgs; + var values; + var nargs; + var args; + var clbk; + var len; + var v; + var s; + var i; + var j; + + nargs = arguments.length; + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + } + nargs -= 1; + if ( isFunction( arguments[ nargs ] ) ) { + clbk = arguments[ nargs ]; + nargs -= 1; + } else { + 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 ]; + nargs -= 2; + } + getters = []; + strides = []; + args = []; + + // 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 ) ); + 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 weren't provided a collection argument, all arguments are "broadcasted"... + if ( len === void 0 ) { + len = 1; + } + // 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 ) { + 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 ); + } + // Initialize an array containing values for generating an interpolated format string: + values = nulls( nargs+2 ); // [ str, v0, v1, ..., vN, result ] + values[ 0 ] = str; + + // 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 ] + + // 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++ ) { + // 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 ]; + } + // 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 ) ); + } +} + + +// 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..f797589098d0 --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/console/log-each-map", + "version": "0.0.0", + "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", + "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", + "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 new file mode 100644 index 000000000000..b758bf72e00e --- /dev/null +++ b/lib/node_modules/@stdlib/console/log-each-map/test/test.js @@ -0,0 +1,641 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +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 a string for the first argument (binary)', 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, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a string for the first argument (n-ary)', 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 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 provided a callback argument which is not a function (binary, 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', 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 ) { + 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 badValue( value ) { + return function badValue() { + logEachMap( '%d, %d', value, [ 1, 2, 3, 4 ], noop ); + }; + } +}); + +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; + 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 value' ); + t.end(); + + function scale( v ) { + return v * 2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +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; + 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 value' ); + t.end(); + + function sum( v1, v2 ) { + return v1 + v2; + } + + function logger( str ) { + actual.push( str ); + } +}); + +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; + 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 value' ); + t.end(); + + function sum( v1, v2, v3 ) { + return v1 + v2 + v3; + } + + function logger( str ) { + actual.push( str ); + } +}); + +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 ]; + 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 = %d', x, y, z, w, sum ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + 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 ) { + actual.push( str ); + } +}); + +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 + }); + + y = [ 1, 2, 3 ]; + expected = [ '5 + 1 = 6', '5 + 2 = 7', '5 + 3 = 8' ]; + actual = []; + + logEachMap( '%d + %d = %d', 5, 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 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; + 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 value' ); + t.end(); + + function scale( v ) { + return v * this.factor; // eslint-disable-line no-invalid-this + } + + function logger( str ) { + actual.push( str ); + } +});