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/cunone-by` #2337

Open kgryte opened 1 month ago

kgryte commented 1 month ago

Description

This RFC proposes adding the package @stdlib/iter/cunone-by, which cumulatively tests whether no 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 = iterCuNoneBy( arr, isPositive );

var v = it.next().value;
// returns true

v = it.next().value;
// returns true

v = it.next().value;
// returns true

v = it.next().value;
// returns false

v = it.next().value;
// returns false

var bool = it.next().done;
// returns true

The predicate function should be provided two arguments:

Related Issues

No.

Questions

No.

Other

Checklist

Ad11xx commented 2 weeks ago

Hi @kgryte , can I solve this?

kgryte commented 2 weeks ago

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

Ad11xx commented 2 weeks ago

Thanks a lot! if it is possible is there any file I can refer to regarding the code practices?

kgryte commented 2 weeks ago

Yes, you should look at both @stdlib/iter/none-by (which is a sink iterator) and @stdlib/iter/for-each, which is a transform iterator. The package you are planning to add should be a combination of the two.