Skip to content

Commit edddb49

Browse files
committed
Add support for complex number arrays
1 parent 7301f5c commit edddb49

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

lib/node_modules/@stdlib/array/to-circular-iterator/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ v = it.next().value;
167167

168168
The invoked function is provided four arguments:
169169

170-
- `value`: iterated value
171-
- `index`: iterated value index
172-
- `n`: iteration count
173-
- `src`: source array-like object
170+
- **value**: iterated value.
171+
- **index**: iterated value index.
172+
- **n**: iteration count.
173+
- **src**: source array-like object.
174174

175175
```javascript
176176
function fcn( v, i ) {
@@ -234,6 +234,7 @@ var count = ctx.count;
234234
- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use a custom iterator.
235235
- 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.
236236
- 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.
237+
- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]).
237238

238239
</section>
239240

@@ -308,6 +309,8 @@ while ( true ) {
308309

309310
<section class="links">
310311

312+
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64
313+
311314
<!-- <related-links> -->
312315

313316
[@stdlib/array/to-iterator]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator

lib/node_modules/@stdlib/array/to-circular-iterator/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type Binary = ( value: any, index: number ) => any;
7373
* @param n - iteration count
7474
* @returns iterator value
7575
*/
76-
type Tertiary = ( value: any, index: number, n: number ) => any;
76+
type Ternary = ( value: any, index: number, n: number ) => any;
7777

7878
/**
7979
* Map function invoked for each iterated value.
@@ -95,7 +95,7 @@ type Quaternary = ( value: any, index: number, n: number, src: ArrayLike<any> )
9595
* @param src - source array-like object
9696
* @returns iterator value
9797
*/
98-
type MapFunction = Nullary | Unary | Binary | Tertiary | Quaternary;
98+
type MapFunction = Nullary | Unary | Binary | Ternary | Quaternary;
9999

100100
/**
101101
* Returns an iterator which repeatedly iterates over each element in an array-like object.

lib/node_modules/@stdlib/array/to-circular-iterator/lib/main.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var isCollection = require( '@stdlib/assert/is-collection' );
2727
var isObject = require( '@stdlib/assert/is-plain-object' );
2828
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2929
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
30+
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
3031

3132

3233
// MAIN //
@@ -68,6 +69,7 @@ function circarray2iterator( src ) {
6869
var iter;
6970
var FLG;
7071
var fcn;
72+
var get;
7173
var i;
7274
if ( !isCollection( src ) ) {
7375
throw new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + src + '`.' );
@@ -131,6 +133,9 @@ function circarray2iterator( src ) {
131133
if ( iteratorSymbol ) {
132134
setReadOnly( iter, iteratorSymbol, factory );
133135
}
136+
// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):
137+
get = arraylike2object( src ).getter;
138+
134139
return iter;
135140

136141
/**
@@ -148,7 +153,7 @@ function circarray2iterator( src ) {
148153
};
149154
}
150155
return {
151-
'value': fcn.call( thisArg, src[ i ], i, count, src ),
156+
'value': fcn.call( thisArg, get( src, i ), i, count, src ),
152157
'done': false
153158
};
154159
}
@@ -171,7 +176,7 @@ function circarray2iterator( src ) {
171176
};
172177
}
173178
return {
174-
'value': fcn.call( thisArg, src[ i ], i, count, src ),
179+
'value': fcn.call( thisArg, get( src, i ), i, count, src ),
175180
'done': false
176181
};
177182
}
@@ -191,7 +196,7 @@ function circarray2iterator( src ) {
191196
};
192197
}
193198
return {
194-
'value': src[ i ],
199+
'value': get( src, i ),
195200
'done': false
196201
};
197202
}
@@ -214,7 +219,7 @@ function circarray2iterator( src ) {
214219
};
215220
}
216221
return {
217-
'value': src[ i ],
222+
'value': get( src, i ),
218223
'done': false
219224
};
220225
}

0 commit comments

Comments
 (0)