stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

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

Open kgryte opened this issue 1 year ago • 6 comments

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

kgryte avatar Jun 08 '24 00:06 kgryte

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 avatar Jun 20 '24 07:06 Apocalypse3007

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

kgryte avatar Jun 29 '24 08:06 kgryte

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:

  1. Initialize Counters: Maintain a count of how many values pass the predicate test.
  2. Iterate Over Values: For each value in the source iterator, apply the predicate function.
  3. Check Predicate: If the predicate returns true, increment the count.
  4. Yield Result: Yield true when the count reaches n; otherwise, yield false.
  5. Completion: Continue iterating and yield true once n values have passed the predicate.

vivek-anand-singh avatar Jul 22 '24 06:07 vivek-anand-singh

@kgryte Please assign this issue to me

vivek-anand-singh avatar Jul 25 '24 09:07 vivek-anand-singh

hey @kgryte , i want to contribute to this project , could you please assign me the issue

ankur-kalita avatar Jul 31 '24 05:07 ankur-kalita

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.

Kaif987 avatar Aug 13 '24 10:08 Kaif987