@stdlib/array-to-strided-iterator 0.0.2 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +51 -7
- package/docs/types/index.d.ts +2 -2
- package/lib/main.js +7 -2
- package/package.json +3 -2
- package/CHANGELOG.md +0 -5
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2022 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
20
20
|
|
|
21
21
|
# Strided Iterator
|
|
22
22
|
|
|
23
|
-
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
|
|
23
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
24
24
|
|
|
25
25
|
> Create an [iterator][mdn-iterator-protocol] from a strided array-like object.
|
|
26
26
|
|
|
@@ -107,10 +107,10 @@ v = it.next().value;
|
|
|
107
107
|
|
|
108
108
|
The invoked function is provided four arguments:
|
|
109
109
|
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
110
|
+
- **value**: iterated value.
|
|
111
|
+
- **index**: iterated value index.
|
|
112
|
+
- **n**: iteration count (zero-based).
|
|
113
|
+
- **src**: source array-like object.
|
|
114
114
|
|
|
115
115
|
```javascript
|
|
116
116
|
function fcn( v, i ) {
|
|
@@ -174,6 +174,7 @@ var count = ctx.count;
|
|
|
174
174
|
- If provided a generic `array`, the returned [iterator][mdn-iterator-protocol] does **not** ignore holes. To achieve greater performance for sparse arrays, use a custom [iterator][mdn-iterator-protocol].
|
|
175
175
|
- A returned [iterator][mdn-iterator-protocol] does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an [iterator][mdn-iterator-protocol]. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned [iterator][mdn-iterator-protocol].
|
|
176
176
|
- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined [iterator][mdn-iterator-protocol], invoke this method directly.
|
|
177
|
+
- The returned [iterator][mdn-iterator-protocol] supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]).
|
|
177
178
|
|
|
178
179
|
</section>
|
|
179
180
|
|
|
@@ -226,6 +227,21 @@ while ( true ) {
|
|
|
226
227
|
|
|
227
228
|
<!-- /.references -->
|
|
228
229
|
|
|
230
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
231
|
+
|
|
232
|
+
<section class="related">
|
|
233
|
+
|
|
234
|
+
* * *
|
|
235
|
+
|
|
236
|
+
## See Also
|
|
237
|
+
|
|
238
|
+
- <span class="package-name">[`@stdlib/array/from-iterator`][@stdlib/array/from-iterator]</span><span class="delimiter">: </span><span class="description">create (or fill) an array from an iterator.</span>
|
|
239
|
+
- <span class="package-name">[`@stdlib/array/to-iterator`][@stdlib/array/to-iterator]</span><span class="delimiter">: </span><span class="description">create an iterator from an array-like object.</span>
|
|
240
|
+
|
|
241
|
+
</section>
|
|
242
|
+
|
|
243
|
+
<!-- /.related -->
|
|
244
|
+
|
|
229
245
|
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
230
246
|
|
|
231
247
|
|
|
@@ -239,6 +255,10 @@ This package is part of [stdlib][stdlib], a standard library for JavaScript and
|
|
|
239
255
|
|
|
240
256
|
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
241
257
|
|
|
258
|
+
#### Community
|
|
259
|
+
|
|
260
|
+
[![Chat][chat-image]][chat-url]
|
|
261
|
+
|
|
242
262
|
---
|
|
243
263
|
|
|
244
264
|
## License
|
|
@@ -248,7 +268,7 @@ See [LICENSE][stdlib-license].
|
|
|
248
268
|
|
|
249
269
|
## Copyright
|
|
250
270
|
|
|
251
|
-
Copyright © 2016-
|
|
271
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
252
272
|
|
|
253
273
|
</section>
|
|
254
274
|
|
|
@@ -267,9 +287,23 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
267
287
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-to-strided-iterator/main.svg
|
|
268
288
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-to-strided-iterator?branch=main
|
|
269
289
|
|
|
270
|
-
|
|
290
|
+
<!--
|
|
291
|
+
|
|
292
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/array-to-strided-iterator.svg
|
|
271
293
|
[dependencies-url]: https://david-dm.org/stdlib-js/array-to-strided-iterator/main
|
|
272
294
|
|
|
295
|
+
-->
|
|
296
|
+
|
|
297
|
+
[umd]: https://github.com/umdjs/umd
|
|
298
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
299
|
+
|
|
300
|
+
[deno-url]: https://github.com/stdlib-js/array-to-strided-iterator/tree/deno
|
|
301
|
+
[umd-url]: https://github.com/stdlib-js/array-to-strided-iterator/tree/umd
|
|
302
|
+
[esm-url]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm
|
|
303
|
+
|
|
304
|
+
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
305
|
+
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
306
|
+
|
|
273
307
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
274
308
|
|
|
275
309
|
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
@@ -278,6 +312,16 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
278
312
|
|
|
279
313
|
[mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
|
|
280
314
|
|
|
315
|
+
[@stdlib/array/complex64]: https://www.npmjs.com/package/@stdlib/array-complex64
|
|
316
|
+
|
|
317
|
+
<!-- <related-links> -->
|
|
318
|
+
|
|
319
|
+
[@stdlib/array/from-iterator]: https://www.npmjs.com/package/@stdlib/array-from-iterator
|
|
320
|
+
|
|
321
|
+
[@stdlib/array/to-iterator]: https://www.npmjs.com/package/@stdlib/array-to-iterator
|
|
322
|
+
|
|
323
|
+
<!-- </related-links> -->
|
|
324
|
+
|
|
281
325
|
</section>
|
|
282
326
|
|
|
283
327
|
<!-- /.links -->
|
package/docs/types/index.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ type Binary = ( value: any, index: number ) => any;
|
|
|
58
58
|
* @param n - iteration count (zero-based)
|
|
59
59
|
* @returns iterator value
|
|
60
60
|
*/
|
|
61
|
-
type
|
|
61
|
+
type Ternary = ( value: any, index: number, n: number ) => any;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Map function invoked for each iterated value.
|
|
@@ -80,7 +80,7 @@ type Quaternary = ( value: any, index: number, n: number, src: ArrayLike<any> )
|
|
|
80
80
|
* @param src - source array-like object
|
|
81
81
|
* @returns iterator value
|
|
82
82
|
*/
|
|
83
|
-
type MapFunction = Nullary | Unary | Binary |
|
|
83
|
+
type MapFunction = Nullary | Unary | Binary | Ternary | Quaternary;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* Returns an iterator which iterates over elements in an array-like object according to specified stride parameters.
|
package/lib/main.js
CHANGED
|
@@ -26,6 +26,7 @@ var isCollection = require( '@stdlib/assert-is-collection' );
|
|
|
26
26
|
var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
|
|
27
27
|
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
|
|
28
28
|
var iteratorSymbol = require( '@stdlib/symbol-iterator' );
|
|
29
|
+
var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
// MAIN //
|
|
@@ -72,6 +73,7 @@ function stridedarray2iterator( N, src, stride, offset ) {
|
|
|
72
73
|
var FLG;
|
|
73
74
|
var fcn;
|
|
74
75
|
var idx;
|
|
76
|
+
var get;
|
|
75
77
|
var i;
|
|
76
78
|
if ( !isNonNegativeInteger( N ) ) {
|
|
77
79
|
throw new TypeError( 'invalid argument. First argument must be a nonnegative integer. Value: `' + N + '`.' );
|
|
@@ -108,6 +110,9 @@ function stridedarray2iterator( N, src, stride, offset ) {
|
|
|
108
110
|
if ( iteratorSymbol ) {
|
|
109
111
|
setReadOnly( iter, iteratorSymbol, factory );
|
|
110
112
|
}
|
|
113
|
+
// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):
|
|
114
|
+
get = arraylike2object( src ).getter;
|
|
115
|
+
|
|
111
116
|
return iter;
|
|
112
117
|
|
|
113
118
|
/**
|
|
@@ -124,7 +129,7 @@ function stridedarray2iterator( N, src, stride, offset ) {
|
|
|
124
129
|
'done': true
|
|
125
130
|
};
|
|
126
131
|
}
|
|
127
|
-
v = fcn.call( thisArg, src
|
|
132
|
+
v = fcn.call( thisArg, get( src, idx ), idx, i, src );
|
|
128
133
|
idx += stride;
|
|
129
134
|
return {
|
|
130
135
|
'value': v,
|
|
@@ -146,7 +151,7 @@ function stridedarray2iterator( N, src, stride, offset ) {
|
|
|
146
151
|
'done': true
|
|
147
152
|
};
|
|
148
153
|
}
|
|
149
|
-
v = src
|
|
154
|
+
v = get( src, idx );
|
|
150
155
|
idx += stride;
|
|
151
156
|
return {
|
|
152
157
|
'value': v,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/array-to-strided-iterator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Create an iterator from a strided array-like object.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"examples": "make examples",
|
|
29
29
|
"benchmark": "make benchmark"
|
|
30
30
|
},
|
|
31
|
-
"homepage": "https://
|
|
31
|
+
"homepage": "https://stdlib.io",
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
34
|
"url": "git://github.com/stdlib-js/array-to-strided-iterator.git"
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@stdlib/array-base-arraylike2object": "^0.0.x",
|
|
40
41
|
"@stdlib/assert-is-collection": "^0.0.x",
|
|
41
42
|
"@stdlib/assert-is-function": "^0.0.x",
|
|
42
43
|
"@stdlib/assert-is-integer": "^0.0.x",
|