[RFC]: add `@stdlib/iter/cusome-by`
Description
This RFC proposes adding the package @stdlib/iter/cusome-by, which cumulatively tests whether at least n iterated values pass a test implemented by a predicate function. The returned iterator should be a transform iterator, continuing to iterate while source iterator values are available.
var array2iterator = require( '@stdlib/array/to-iterator' );
function isPositive( value ) {
return ( value > 0 );
}
var arr = array2iterator( [ 0, 0, 0, 1, 1 ] );
var it = iterCuSomeBy( arr, 2, isPositive );
var v = it.next().value;
// returns false
v = it.next().value;
// returns false
v = it.next().value;
// returns false
v = it.next().value;
// returns false
v = it.next().value;
// returns true
var bool = it.next().done;
// returns true
The predicate function should be provided two arguments:
- value: the iterated value.
- index: iteration index (zero-based).
Related Issues
No.
Questions
No.
Other
- See also
@stdlib/iter/some-by
Checklist
- [X] I have read and understood the Code of Conduct.
- [X] Searched for existing issues and pull requests.
- [X] The issue name begins with
RFC:.
Hey, I think I am able to find the solution to the problem you are addressing but since I am new to open source I am not able to figure out how do I add the solution to the code and where to add the file of iter/CusomeBy in the source code. So, if you can help me with that I will be very grateful
Thanks
@Apocalypse3007 You can find similar packages (not just files) in the following project directory: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/iter.
Your contribution should be a package, not just the implementation file. I suggest looking through the packages which already exist in that directory and then structure your contribution based on whatever seems closest. Generally, when adding a new package, I copy-paste an existing package to the desired folder and then modify each file in accordance with the package's intent.
I would like to work on this RFC to add the package @stdlib/iter/cusome-by. Could you please assign this issue to me?
For the implementation, I plan to:
- Initialize Counters: Maintain a count of how many values pass the predicate test.
- Iterate Over Values: For each value in the source iterator, apply the predicate function.
- Check Predicate: If the predicate returns true, increment the count.
-
Yield Result: Yield
truewhen the count reachesn; otherwise, yieldfalse. -
Completion: Continue iterating and yield
trueoncenvalues have passed the predicate.
@kgryte Please assign this issue to me
hey @kgryte , i want to contribute to this project , could you please assign me the issue
Hey can I work on this issue and submit a new PR? I saw that the previous PR submitted had some problems that have not yet been solved.