@stdlib/array-to-iterator 0.0.5 → 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 +48 -5
- package/docs/types/index.d.ts +2 -2
- package/lib/main.js +7 -2
- package/package.json +6 -1
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
|
# array2iterator
|
|
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 from an array-like object.
|
|
26
26
|
|
|
@@ -101,9 +101,9 @@ v = it.next().value;
|
|
|
101
101
|
|
|
102
102
|
The invoked function is provided three arguments:
|
|
103
103
|
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
104
|
+
- **value**: iterated value.
|
|
105
|
+
- **index**: iterated value index.
|
|
106
|
+
- **src**: source array-like object.
|
|
107
107
|
|
|
108
108
|
```javascript
|
|
109
109
|
function fcn( v, i ) {
|
|
@@ -167,6 +167,7 @@ var count = ctx.count;
|
|
|
167
167
|
- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use [`@stdlib/array/to-sparse-iterator`][@stdlib/array/to-sparse-iterator].
|
|
168
168
|
- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator.
|
|
169
169
|
- 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, invoke this method directly.
|
|
170
|
+
- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]).
|
|
170
171
|
|
|
171
172
|
</section>
|
|
172
173
|
|
|
@@ -219,6 +220,23 @@ while ( true ) {
|
|
|
219
220
|
|
|
220
221
|
<!-- /.references -->
|
|
221
222
|
|
|
223
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
224
|
+
|
|
225
|
+
<section class="related">
|
|
226
|
+
|
|
227
|
+
* * *
|
|
228
|
+
|
|
229
|
+
## See Also
|
|
230
|
+
|
|
231
|
+
- <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>
|
|
232
|
+
- <span class="package-name">[`@stdlib/array/to-circular-iterator`][@stdlib/array/to-circular-iterator]</span><span class="delimiter">: </span><span class="description">create an iterator which repeatedly iterates over the elements of an array-like object.</span>
|
|
233
|
+
- <span class="package-name">[`@stdlib/array/to-iterator-right`][@stdlib/array/to-iterator-right]</span><span class="delimiter">: </span><span class="description">create an iterator from an array-like object, iterating from right to left.</span>
|
|
234
|
+
- <span class="package-name">[`@stdlib/array/to-strided-iterator`][@stdlib/array/to-strided-iterator]</span><span class="delimiter">: </span><span class="description">create an iterator from a strided array-like object.</span>
|
|
235
|
+
|
|
236
|
+
</section>
|
|
237
|
+
|
|
238
|
+
<!-- /.related -->
|
|
239
|
+
|
|
222
240
|
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
223
241
|
|
|
224
242
|
|
|
@@ -245,7 +263,7 @@ See [LICENSE][stdlib-license].
|
|
|
245
263
|
|
|
246
264
|
## Copyright
|
|
247
265
|
|
|
248
|
-
Copyright © 2016-
|
|
266
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
249
267
|
|
|
250
268
|
</section>
|
|
251
269
|
|
|
@@ -264,9 +282,20 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
264
282
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-to-iterator/main.svg
|
|
265
283
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-to-iterator?branch=main
|
|
266
284
|
|
|
285
|
+
<!--
|
|
286
|
+
|
|
267
287
|
[dependencies-image]: https://img.shields.io/david/stdlib-js/array-to-iterator.svg
|
|
268
288
|
[dependencies-url]: https://david-dm.org/stdlib-js/array-to-iterator/main
|
|
269
289
|
|
|
290
|
+
-->
|
|
291
|
+
|
|
292
|
+
[umd]: https://github.com/umdjs/umd
|
|
293
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
294
|
+
|
|
295
|
+
[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno
|
|
296
|
+
[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd
|
|
297
|
+
[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm
|
|
298
|
+
|
|
270
299
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
271
300
|
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
272
301
|
|
|
@@ -278,6 +307,20 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
278
307
|
|
|
279
308
|
[@stdlib/array/to-sparse-iterator]: https://www.npmjs.com/package/@stdlib/array-to-sparse-iterator
|
|
280
309
|
|
|
310
|
+
[@stdlib/array/complex64]: https://www.npmjs.com/package/@stdlib/array-complex64
|
|
311
|
+
|
|
312
|
+
<!-- <related-links> -->
|
|
313
|
+
|
|
314
|
+
[@stdlib/array/from-iterator]: https://www.npmjs.com/package/@stdlib/array-from-iterator
|
|
315
|
+
|
|
316
|
+
[@stdlib/array/to-circular-iterator]: https://www.npmjs.com/package/@stdlib/array-to-circular-iterator
|
|
317
|
+
|
|
318
|
+
[@stdlib/array/to-iterator-right]: https://www.npmjs.com/package/@stdlib/array-to-iterator-right
|
|
319
|
+
|
|
320
|
+
[@stdlib/array/to-strided-iterator]: https://www.npmjs.com/package/@stdlib/array-to-strided-iterator
|
|
321
|
+
|
|
322
|
+
<!-- </related-links> -->
|
|
323
|
+
|
|
281
324
|
</section>
|
|
282
325
|
|
|
283
326
|
<!-- /.links -->
|
package/docs/types/index.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ type Binary = ( value: any, index: number ) => any;
|
|
|
58
58
|
* @param src - source array-like object
|
|
59
59
|
* @returns iterator value
|
|
60
60
|
*/
|
|
61
|
-
type
|
|
61
|
+
type Ternary = ( value: any, index: number, src: ArrayLike<any> ) => any;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Map function invoked for each iterated value.
|
|
@@ -68,7 +68,7 @@ type Tertiary = ( value: any, index: number, src: ArrayLike<any> ) => any;
|
|
|
68
68
|
* @param src - source array-like object
|
|
69
69
|
* @returns iterator value
|
|
70
70
|
*/
|
|
71
|
-
type MapFunction = Nullary | Unary | Binary |
|
|
71
|
+
type MapFunction = Nullary | Unary | Binary | Ternary;
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Returns an iterator which iterates over each element in an array-like object.
|
package/lib/main.js
CHANGED
|
@@ -24,6 +24,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-propert
|
|
|
24
24
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
25
25
|
var isCollection = require( '@stdlib/assert-is-collection' );
|
|
26
26
|
var iteratorSymbol = require( '@stdlib/symbol-iterator' );
|
|
27
|
+
var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
// MAIN //
|
|
@@ -57,6 +58,7 @@ function array2iterator( src ) {
|
|
|
57
58
|
var iter;
|
|
58
59
|
var FLG;
|
|
59
60
|
var fcn;
|
|
61
|
+
var get;
|
|
60
62
|
var i;
|
|
61
63
|
if ( !isCollection( src ) ) {
|
|
62
64
|
throw new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + src + '`.' );
|
|
@@ -83,6 +85,9 @@ function array2iterator( src ) {
|
|
|
83
85
|
if ( iteratorSymbol ) {
|
|
84
86
|
setReadOnly( iter, iteratorSymbol, factory );
|
|
85
87
|
}
|
|
88
|
+
// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):
|
|
89
|
+
get = arraylike2object( src ).getter;
|
|
90
|
+
|
|
86
91
|
return iter;
|
|
87
92
|
|
|
88
93
|
/**
|
|
@@ -99,7 +104,7 @@ function array2iterator( src ) {
|
|
|
99
104
|
};
|
|
100
105
|
}
|
|
101
106
|
return {
|
|
102
|
-
'value': fcn.call( thisArg, src
|
|
107
|
+
'value': fcn.call( thisArg, get( src, i ), i, src ),
|
|
103
108
|
'done': false
|
|
104
109
|
};
|
|
105
110
|
}
|
|
@@ -118,7 +123,7 @@ function array2iterator( src ) {
|
|
|
118
123
|
};
|
|
119
124
|
}
|
|
120
125
|
return {
|
|
121
|
-
'value': src
|
|
126
|
+
'value': get( src, i ),
|
|
122
127
|
'done': false
|
|
123
128
|
};
|
|
124
129
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/array-to-iterator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Create an iterator from an array-like object.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -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/symbol-iterator": "^0.0.x",
|
|
@@ -44,9 +45,13 @@
|
|
|
44
45
|
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
48
|
+
"@stdlib/array-complex64": "^0.0.x",
|
|
47
49
|
"@stdlib/array-float64": "^0.0.x",
|
|
48
50
|
"@stdlib/assert-is-iterator-like": "^0.0.x",
|
|
49
51
|
"@stdlib/bench": "^0.0.x",
|
|
52
|
+
"@stdlib/complex-float32": "^0.0.x",
|
|
53
|
+
"@stdlib/complex-imagf": "^0.0.x",
|
|
54
|
+
"@stdlib/complex-realf": "^0.0.x",
|
|
50
55
|
"@stdlib/math-base-assert-is-nan": "^0.0.x",
|
|
51
56
|
"@stdlib/random-base-randu": "^0.0.x",
|
|
52
57
|
"@stdlib/utils-inmap": "^0.0.x",
|