Skip to content

Commit c8b581b

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into chore/fixed-lint-errors-6083
2 parents ed74f89 + 6010481 commit c8b581b

File tree

78 files changed

+3127
-376
lines changed

Some content is hidden

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

78 files changed

+3127
-376
lines changed

lib/node_modules/@stdlib/console/docs/types/index.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ interface Namespace {
5353
* @throws provided collections must have the same length
5454
*
5555
* @example
56-
* var ns.logEach = require( '@stdlib/console/log-each' );
57-
*
5856
* var x = [ 1, 2, 3 ];
5957
* var y = [ 4, 5, 6 ];
6058
*

lib/node_modules/@stdlib/console/lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ setReadOnly( ns, 'log', require( '@stdlib/console/log' ) );
5858
*/
5959
setReadOnly( ns, 'logEach', require( '@stdlib/console/log-each' ) );
6060

61+
/**
62+
* @name logEachMap
63+
* @memberof ns
64+
* @readonly
65+
* @type {Function}
66+
* @see {@link module:@stdlib/console/log-each-map}
67+
*/
68+
setReadOnly( ns, 'logEachMap', require( '@stdlib/console/log-each-map' ) );
69+
6170

6271
// EXPORTS //
6372

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# logEachMap
22+
23+
> Insert array element values and the result of a callback function into a format string and print the result.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var logEachMap = require( '@stdlib/console/log-each-map' );
41+
```
42+
43+
#### logEachMap( str\[, ...args], clbk\[, thisArg] )
44+
45+
Inserts array element values and the result of a callback function into a format string and prints the result.
46+
47+
```javascript
48+
function add( a, b ) {
49+
return a + b;
50+
}
51+
52+
var x = [ 1, 2, 3 ];
53+
var y = [ 4, 5, 6 ];
54+
55+
logEachMap( '%d + %d = %d', x, y, add );
56+
// e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n'
57+
```
58+
59+
The function accepts the following arguments:
60+
61+
- **str**: format string.
62+
- **args**: input arrays _(optional)_.
63+
- **clbk**: callback function.
64+
- **thisArg**: callback execution context _(optional)_.
65+
66+
To set the callback execution context, provide a `thisArg`.
67+
68+
<!-- eslint-disable no-invalid-this -->
69+
70+
```javascript
71+
function count( x, y ) {
72+
this.count += 1;
73+
return x + y;
74+
}
75+
76+
var x = [ 1, 2, 3 ];
77+
var y = [ 4, 5, 6 ];
78+
79+
var ctx = {
80+
'count': 0
81+
};
82+
83+
logEachMap( '%d + %d = %d', x, y, count, ctx );
84+
// e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n'
85+
86+
var v = ctx.count;
87+
// returns 3
88+
```
89+
90+
If an interpolated argument is not an array-like object, the argument is broadcasted for each iteration.
91+
92+
```javascript
93+
function multiply( x, y ) {
94+
return x * y;
95+
}
96+
97+
var x = [ 1, 2, 3 ];
98+
var y = 2;
99+
100+
logEachMap( '%d * %d = %d', x, y, multiply );
101+
// e.g., => '1 * 2 = 2\n2 * 2 = 4\n3 * 2 = 6\n'
102+
```
103+
104+
The callback function is provided the following arguments:
105+
106+
- **arg0**: current array element for the first broadcasted array.
107+
- **arg1**: current array element for the second broadcasted array.
108+
- **...argN**: current array element for the nth broadcasted array.
109+
- **index**: current element index.
110+
- **arrays**: broadcasted arrays. If an argument was broadcasted, the corresponding array is a single-element generic array containing the original element.
111+
112+
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.
113+
114+
</section>
115+
116+
<!-- /.usage -->
117+
118+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
119+
120+
<section class="notes">
121+
122+
## Notes
123+
124+
- If the function is provided array-like objects of unequal lengths, the function throws an error.
125+
- The function supports array-like objects supporting the accessor protocol (e.g., [`Complex128Array`][@stdlib/array/complex128], [`Complex64Array`][@stdlib/array/complex64], etc).
126+
127+
</section>
128+
129+
<!-- /.notes -->
130+
131+
<!-- Package usage examples. -->
132+
133+
<section class="examples">
134+
135+
## Examples
136+
137+
<!-- eslint no-undef: "error" -->
138+
139+
```javascript
140+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
141+
var logEachMap = require( '@stdlib/console/log-each-map' );
142+
143+
function add( x, y ) {
144+
return x + y;
145+
}
146+
147+
var x = discreteUniform( 10, -50, 50, {
148+
'dtype': 'float64'
149+
});
150+
var y = discreteUniform( 10, -50, 50, {
151+
'dtype': 'float64'
152+
});
153+
154+
logEachMap( '%d + %d = %d', x, y, add );
155+
```
156+
157+
</section>
158+
159+
<!-- /.examples -->
160+
161+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
162+
163+
<section class="references">
164+
165+
</section>
166+
167+
<!-- /.references -->
168+
169+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
170+
171+
<section class="related">
172+
173+
</section>
174+
175+
<!-- /.related -->
176+
177+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
178+
179+
<section class="links">
180+
181+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
182+
183+
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64
184+
185+
</section>
186+
187+
<!-- /.links -->
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var proxyquire = require( 'proxyquire' );
24+
var bench = require( '@stdlib/bench' );
25+
var pkg = require( './../package.json' ).name;
26+
27+
28+
// FUNCTIONS //
29+
30+
/**
31+
* Identity function.
32+
*
33+
* @private
34+
* @param {*} x - input value
35+
* @returns {*} input value
36+
*/
37+
function clbk( x ) {
38+
return x;
39+
}
40+
41+
42+
// MAIN //
43+
44+
bench( pkg+'::no_collections', function benchmark( b ) {
45+
var logEachMap;
46+
var i;
47+
48+
logEachMap = proxyquire( './../lib/main.js', {
49+
'@stdlib/console/log': logger
50+
});
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
logEachMap( '%d -> %d', i, clbk );
55+
}
56+
b.toc();
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
60+
function logger( str ) {
61+
if ( typeof str !== 'string' ) {
62+
b.fail( 'should return a string' );
63+
}
64+
}
65+
});
66+
67+
bench( pkg+'::collections:len=1', function benchmark( b ) {
68+
var logEachMap;
69+
var i;
70+
71+
logEachMap = proxyquire( './../lib/main.js', {
72+
'@stdlib/console/log': logger
73+
});
74+
75+
b.tic();
76+
for ( i = 0; i < b.iterations; i++ ) {
77+
logEachMap( '%d -> %d', [ i ], clbk );
78+
}
79+
b.toc();
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
83+
function logger( str ) {
84+
if ( typeof str !== 'string' ) {
85+
b.fail( 'should return a string' );
86+
}
87+
}
88+
});
89+
90+
bench( pkg+'::collections:len=2', function benchmark( b ) {
91+
var logEachMap;
92+
var i;
93+
94+
logEachMap = proxyquire( './../lib/main.js', {
95+
'@stdlib/console/log': logger
96+
});
97+
98+
b.tic();
99+
for ( i = 0; i < b.iterations; i++ ) {
100+
logEachMap( '%d + %d = %d', [ i ], [ i + 1 ], sum );
101+
}
102+
b.toc();
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
106+
function sum( x, y ) {
107+
return x + y;
108+
}
109+
110+
function logger( str ) {
111+
if ( typeof str !== 'string' ) {
112+
b.fail( 'should return a string' );
113+
}
114+
}
115+
});

0 commit comments

Comments
 (0)