stdlib-js / stdlib

✨ Standard library for JavaScript and Node.js. ✨
https://stdlib.io
Apache License 2.0
4.18k stars 405 forks source link

[RFC]: add `@stdlib/iter/cusome-by` #2338

Open kgryte opened 1 month ago

kgryte commented 1 month ago

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:

Related Issues

No.

Questions

No.

Other

Checklist

Apocalypse3007 commented 2 weeks ago

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

kgryte commented 1 week ago

@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.