stdlib-js / stdlib

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

[RFC]: add `@stdlib/iter/cuany-by` #2335

Open kgryte opened 2 months ago

kgryte commented 2 months ago

Description

This RFC proposes adding the package @stdlib/iter/cuany-by, which cumulatively tests whether at least one iterated value passes 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, 0 ] );

var it = iterCuAnyBy( arr, 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 true

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

pra2107tham commented 1 month ago

Hii, I would like to start my open source contribution by solving this issue. Can anyone assign me to it?

kgryte commented 1 month ago

@pra2107tham Thanks for volunteering to work on this. Please feel free to submit a PR implementing this feature.

pra2107tham commented 1 month ago

Can you please tell me step by step way of solving this issue. i am not getting on how to do it?

kgryte commented 1 month ago

@pra2107tham I suggest copying the package iter/cuany to iter/cuany-by and then refactoring to support a callback argument. The signature of the main export should match iter/any-by, but the behavior should be similar to cuany.

pra2107tham commented 1 month ago

Where is the predicate function in the code? i am not able to find it?

kgryte commented 1 month ago

There isn't a predicate function in iter/cuany. The purpose of this RFC is to create a separate package exposing a transform iterator which is similiar to cuany but provides an implementation supporting a predicate function. An example of a sink iterator which supports a predicate function is any-by. To implement this package, you need to borrow the interface of any-by and extend the behavior of cuany.

pra2107tham commented 1 month ago

I have made a PR, can you please check it up, all the test cases passes. Waiting for your approval

pra2107tham commented 1 month ago

Sir idk which errors r coming as lint, I dont have any idea, can you please help me?