stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

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

Open kgryte opened this issue 1 year ago • 9 comments

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:

  • value: the iterated value.
  • index: iteration index (zero-based).

Related Issues

No.

Questions

No.

Other

  • See also @stdlib/iter/any-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:.

kgryte avatar Jun 08 '24 00:06 kgryte

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

pra2107tham avatar Jul 08 '24 18:07 pra2107tham

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

kgryte avatar Jul 08 '24 18:07 kgryte

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

pra2107tham avatar Jul 09 '24 19:07 pra2107tham

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

kgryte avatar Jul 09 '24 22:07 kgryte

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

pra2107tham avatar Jul 10 '24 03:07 pra2107tham

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.

kgryte avatar Jul 10 '24 05:07 kgryte

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

pra2107tham avatar Jul 10 '24 06:07 pra2107tham

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

pra2107tham avatar Jul 10 '24 08:07 pra2107tham

Hey @kgryte can i solve this issue since it is not solved for long time

gururaj1512 avatar Aug 25 '24 07:08 gururaj1512