Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add values method to array/fixed-endian-factory #3294

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

yuvi-mittal
Copy link

The values() method was added to the typed array prototype to allow iteration over the array's values. This method returns an iterator, which can be used in a for...of loop or with next() calls to access each value in the array sequentially. This change simplifies the process of iterating over typed arrays, ensuring that code interacting with them is more readable and easier to maintain.

Fixes: #3161

Resolves #3161

Description

What is the purpose of this pull request?

This pull request:

add values method to @stdlib/array/fixed-endian-factory

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

The `values()` method was added to the typed array prototype to allow iteration over the array's values.
This method returns an iterator, which can be used in a `for...of` loop or with `next()` calls to access each value in the array sequentially.
This change simplifies the process of iterating over typed arrays, ensuring that code interacting with them is more readable and easier to maintain.

Fixes: stdlib-js#123
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Nov 28, 2024

Coverage Report

Package Statements Branches Functions Lines
array/fixed-endian-factory $\color{red}1222/1473$
$\color{green}+82.96\%$
$\color{red}162/174$
$\color{green}+93.10\%$
$\color{red}26/36$
$\color{green}+72.22\%$
$\color{red}1222/1473$
$\color{green}+82.96\%$

The above coverage report was generated for the changes in this PR.

@MeastroZI
Copy link
Contributor

Please change the PR title to
feat: add values method to array/fixed-endian-factory

@yuvi-mittal yuvi-mittal changed the title feat(typed-array): add values() method to iterate over array values feat: add values method to array/fixed-endian-factory Nov 28, 2024
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.values();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

* @throws {TypeError} `this` must be a typed array instance
* @returns {Object} iterator for array elements
*/
setReadOnly(TypedArray.prototype, 'values', function values() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setReadOnly(TypedArray.prototype, 'values', function values() {
setReadOnly( TypedArray.prototype, 'values', function values() {

var buf = this._buffer;
var len = this._length;

if (!isTypedArray(this)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!isTypedArray(this)) {
if ( !isTypedArray( this ) ) {

Comment on lines 872 to 897
throw new TypeError(format('invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[dtype[0]], CTOR_NAME));
}

iterator = {
'next': function next() {
if (index < len) {
value = buf[GETTER](index * BYTES_PER_ELEMENT, isLE);
index += 1;
return {
'value': value,
'done': false
};
}
return {
'done': true
};
}
};

iterator[Symbol.iterator] = function iterator() {
return this;
};

return iterator;
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the spaces under the every parans.. same way i have suggested

t.end();
});

tape( 'the `values` method returns an iterator function', function test( t ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case like this is missing

var iterator;
var result;
var ctor = factory( 'float64' );
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] );
var arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );

var iterator;
var result;
var ctor = factory( 'float64' );
var arr = new ctor( 'little-endian', [10.5, 20.5, 30.5] );
Copy link
Contributor

@MeastroZI MeastroZI Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces in square braces [ ... ]

var values = [];
var value;
var ctor = factory( 'float64' );
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces in square braces [ ... ]

values.push( value );
}

t.deepEqual( values, [1.0, 2.0, 3.0, 4.0, 5.0], 'correctly iterates over values' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces in square braces [ ... ] .

please do same for all

@yuvi-mittal
Copy link
Author

@MeastroZI Thanks for the review , i have made the required changes.

@Planeshifter Planeshifter changed the title feat: add values method to array/fixed-endian-factory feat: add values method to array/fixed-endian-factory Dec 1, 2024
@Planeshifter Planeshifter added the Needs Review A pull request which needs code review. label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review A pull request which needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add values method to array/fixed-endian-factory
4 participants