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/cuevery-by` #2336

Open kgryte opened 1 month ago

kgryte commented 1 month ago

Description

This RFC proposes adding the package @stdlib/iter/cuevery-by, which cumulatively tests whether every 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( [ 1, 1, 1, 0, 1 ] );

var it = iterCuEveryBy( 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

bhargav5667 commented 1 week ago

Can i work on this issue

kgryte commented 1 week ago

@bhargav5667 Thanks for volunteering to work on this issue. Yes, please feel free to submit a PR implementing the requested functionality.