Skip to content

feat: add iter/cusome-by #2661

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

Closed

Conversation

vivek-anand-singh
Copy link

Resolves #2338

Description

What is the purpose of this pull request?
The purpose of this pull request is to introduce the @stdlib/iter/cusome-by package, which provides a transform iterator to determine if at least n values from a source iterator satisfy a given predicate function. This new feature enhances the library by allowing cumulative testing of iterated values.

This pull request:

  • adds the feature of cusome-by function for stdib

Related Issues

Does this pull request have any related issues?

  • No

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.

Copy link
Contributor

@stdlib-bot stdlib-bot left a comment

Choose a reason for hiding this comment

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

👋 Hi there! 👋

And thank you for opening your first pull request! We will review it shortly. 🏃 💨

@vivek-anand-singh
Copy link
Author

@kgryte Please review this PR .

Comment on lines +1 to +3
Here's the adapted README.md for `cusome-by`, based on the `some-by` version:

```markdown
Copy link
Member

Choose a reason for hiding this comment

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

This is not how to write README files. Furthermore, the README name is incorrect. We don't uppercase MD.

Comment on lines +201 to +209
* * *

## See Also

- <span class="package-name">[`@stdlib/iter/cuany-by`][@stdlib/iter/cuany-by]</span><span class="delimiter">: </span><span class="description">create an iterator which iteratively applies a test function to iterated values, returning `true` if a test is passed and `false` otherwise.</span>
- <span class="package-name">[`@stdlib/iter/cuevery-by`][@stdlib/iter/cuevery-by]</span><span class="delimiter">: </span><span class="description">create an iterator which iteratively applies a test function to iterated values, returning `false` if a test fails and `true` otherwise.</span>
- <span class="package-name">[`@stdlib/iter/for-each`][@stdlib/iter/for-each]</span><span class="delimiter">: </span><span class="description">create an iterator which invokes a function for each iterated value before returning the iterated value.</span>
- <span class="package-name">[`@stdlib/iter/cunone-by`][@stdlib/iter/cunone-by]</span><span class="delimiter">: </span><span class="description">create an iterator which iteratively applies a test function to iterated values, returning `true` if all values fail and `false` otherwise.</span>
- <span class="package-name">[`@stdlib/iter/cusome`][@stdlib/iter/cusome]</span><span class="delimiter">: </span><span class="description">create an iterator which iteratively checks whether at least `n` iterated values are truthy.</span>
Copy link
Member

Choose a reason for hiding this comment

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

Do not manually edit this section. See the comment at L197. This section should be empty.

Comment on lines +221 to +233
<!-- <related-links> -->

[@stdlib/iter/cuany-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/iter/cuany-by

[@stdlib/iter/cuevery-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/iter/cuevery-by

[@stdlib/iter/for-each]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/iter/for-each

[@stdlib/iter/cunone-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/iter/cunone-by

[@stdlib/iter/cusome]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/iter/cusome

<!-- </related-links> -->
Copy link
Member

Choose a reason for hiding this comment

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

These should be removed.

function predicate( v ) {
return ( v > 0 );
}
});
Copy link
Member

Choose a reason for hiding this comment

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

You did not setup EditorConfig. Please read our contributing guidelines.

@@ -0,0 +1,49 @@
The predicate function is provided two arguments:
Copy link
Member

Choose a reason for hiding this comment

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

This file does not adhere to project conventions. See the REPL text guide in /docs.

/**
* Interface for the returned iterator.
*/
interface CuSomeByIterator extends Iterator {
Copy link
Member

Choose a reason for hiding this comment

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

Why are you doing this? Use TypedIterator from @stdlib/types/iter. Furthermore, if the source iterator is iterable, the returned iterable should also be iterable. See other @stdlib/iter/* packages.

@@ -0,0 +1,106 @@
import iterCuSomeBy = require( './index' );
Copy link
Member

Choose a reason for hiding this comment

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

Missing license header. Incorrect indentation throughout the file.

Comment on lines +104 to +106



Copy link
Member

Choose a reason for hiding this comment

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

Why do you have multiple trailing lines?

break;
}
console.log( v.value );
}
Copy link
Member

Choose a reason for hiding this comment

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

EditorConfig.


// EXPORTS //

module.exports = main;
Copy link
Member

Choose a reason for hiding this comment

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

EditorConfig.

Comment on lines +117 to +120
return {
'value': false,
'done': false
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return {
'value': false,
'done': false
};
return v;


// EXPORTS //

module.exports = iterCuSomeBy;
Copy link
Member

Choose a reason for hiding this comment

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

EditorConfig.

@@ -0,0 +1,73 @@
{
"name": "@stdlib/iter/cusome-by",
Copy link
Member

Choose a reason for hiding this comment

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

Indentation in this file is off.

"cusome",
"transform"
]
}
Copy link
Member

Choose a reason for hiding this comment

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

EditorConfig.

tape( 'the function returns an iterator', function test( t ) {
var it = iterCuSomeBy( array2iterator( [ 1, 1, 0, 0, 1 ] ), 3, predicate );
t.equal( typeof it.next, 'function', 'has next method' );
// t.equal( typeof it.return, 'function', 'has return method' );
Copy link
Member

Choose a reason for hiding this comment

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

Don't leave commented code.


it = iterCuSomeBy( array2iterator( values ), 2, predicate );
t.equal( typeof it.next, 'function', 'has next method' );
// t.equal( typeof it.return, 'function', 'has return method' );
Copy link
Member

Choose a reason for hiding this comment

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

Same thing.

t.equal( typeof r.value, 'boolean', 'returns a boolean' );
t.equal( r.done, false, 'returns expected value' );

// r = it.return();
Copy link
Member

Choose a reason for hiding this comment

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

Why did you do this? Now the test does not test what it is supposed to.

t.equal( typeof r.value, 'boolean', 'returns a boolean' );
t.equal( r.done, false, 'returns expected value' );

// r = it.return( 'finished' );
Copy link
Member

Choose a reason for hiding this comment

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

Same thing.

this.count += 1; // eslint-disable-line no-invalid-this
return ( v > 0 );
}
});
Copy link
Member

Choose a reason for hiding this comment

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

EditorConfig.

Copy link
Member

Choose a reason for hiding this comment

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

Why did you include this file? Remove.

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

This PR needs significant changes before it can be considered for further review. Please study existing packages in @stdlib/iter/* and emulate the style and conventions as closely as possible and as appropriate. And further, please be sure to setup your local dev environment for contributing to stdlib as discussed in the contributing guidelines. It is clear that linting was not setup locally.

@kgryte kgryte added Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. labels Jul 29, 2024
@kgryte kgryte changed the title Cusome by feat: add iter/cusome-by Jul 29, 2024
@kgryte
Copy link
Member

kgryte commented Jul 29, 2024

@vivek-anand-singh Also, in your OP, you removed the checkbox indicating that you have read the contributing guidelines. Without that checkbox, we cannot accept your PR. Please be sure to include that before any further review.

@vivek-anand-singh vivek-anand-singh deleted the cusome-by branch August 13, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add @stdlib/iter/cusome-by
3 participants