From 4b665dc1c8430dd1025e93a2c9abde9fbb940a65 Mon Sep 17 00:00:00 2001 From: Mohammad Kaif Date: Tue, 27 Aug 2024 15:21:48 +0545 Subject: [PATCH 1/5] feat(iter): add `@stdlib/iter/cuevery-by` package This is the initial commit that copies the package from cunone-by package Ref: #2336 CoAuthored-by: Mohammad Kaif --- .../@stdlib/iter/cuevery-by/README.md | 202 ++++++++++ .../iter/cuevery-by/benchmark/benchmark.js | 89 +++++ .../@stdlib/iter/cuevery-by/docs/repl.txt | 64 +++ .../iter/cuevery-by/docs/types/index.d.ts | 97 +++++ .../iter/cuevery-by/docs/types/test.ts | 109 ++++++ .../@stdlib/iter/cuevery-by/examples/index.js | 45 +++ .../@stdlib/iter/cuevery-by/lib/index.js | 65 ++++ .../@stdlib/iter/cuevery-by/lib/main.js | 157 ++++++++ .../@stdlib/iter/cuevery-by/package.json | 68 ++++ .../@stdlib/iter/cuevery-by/test/test.js | 364 ++++++++++++++++++ 10 files changed, 1260 insertions(+) create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/README.md create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/package.json create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/test/test.js diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/README.md b/lib/node_modules/@stdlib/iter/cuevery-by/README.md new file mode 100644 index 00000000000..5f7a5601527 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/README.md @@ -0,0 +1,202 @@ + + +# iterCuNoneBy + +> Create an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuNoneBy = require( '@stdlib/iter/cuevery-by' ); +``` + +#### iterCuNoneBy( iterator, predicate\[, thisArg] ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value fails a test implemented by a `predicate` function. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + return ( v > 0 ); +} + +var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); + +var it = iterCuNoneBy( arr, predicate ); + +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 returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + +A `predicate` function is provided two arguments: + +- **value**: iterated value +- **index**: iteration index (zero-based) + +To set the `predicate` function execution context, provide a `thisArg`. + + + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + this.count += 1; + return ( v < 0 ); +} + +var ctx = { + 'count': 0 +}; + +var it = iterCuNoneBy( array2iterator( [ 1, 2, 3, 4 ] ), predicate, ctx ); +// returns + +var v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +var count = ctx.count; +// returns 4 +``` + + + + + + + +
+ +## Notes + +- A `predicate` function is invoked for each iterated value until the first truthy `predicate` function return value. Upon encountering the first truthy return value, the returned iterator ceases to invoke the `predicate` function and returns `false` for each subsequent iterated value of the provided input `iterator`. + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuNoneBy = require( '@stdlib/iter/cuevery-by' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which cumulatively tests whether every iterated value fails a test: +var it = iterCuNoneBy( riter, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js new file mode 100644 index 00000000000..6ab0a50cb2c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var iterConstant = require( '@stdlib/iter/constant' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var iterCuNoneBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value < 0 ); +} + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var it; + var i; + + it = iterConstant( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterCuNoneBy( it, predicate ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var v; + var i; + + iter = iterCuNoneBy( iterConstant( 3.14 ), predicate ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = iter.next().value; + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt new file mode 100644 index 00000000000..aefc637220f --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt @@ -0,0 +1,64 @@ + +{{alias}}( iterator, predicate[, thisArg] ) + Returns an iterator which cumulatively tests whether every iterated value + fails a test implemented by a predicate function. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + The predicate function is provided two arguments: + + - value: iterated value + - index: iteration index + + A predicate function is invoked for each iterated value until the first + truthy predicate function return value. Upon encountering the first truthy + return value, the returned iterator ceases to invoke the predicate function + and returns `false` for each subsequent iterated value of the provided input + iterator. + + If provided an iterator which does not return any iterated values, the + function returns an iterator which is also empty. + + Parameters + ---------- + iterator: Object + Input iterator. + + predicate: Function + The test function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating + whether the iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 0, 0, 0, 1, 0 ] ); + > function fcn( v ) { return ( v > 0 ); }; + > var it = {{alias}}( arr, fcn ); + > var v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + false + > v = it.next().value + false + + See Also + -------- diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts new file mode 100644 index 00000000000..30635bf1326 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts @@ -0,0 +1,97 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = TypedIterator | TypedIterableIterator; + +/** +* Checks whether an iterated value passes a test. +* +* @returns boolean indicating whether an iterated value passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @returns boolean indicating whether an iterated value passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Predicate = Nullary | Unary | Binary; + +/** +* Returns an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +* +* @param iterator - source iterator +* @param predicate - predicate function +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var it = iterCuNoneBy( array2iterator( [ 0, 0, 0, 1, 0 ] ), 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 +*/ +declare function iterCuNoneBy( iterator: Iterator, predicate: Predicate, thisArg?: ThisParameterType> ): Iterator; + + +// EXPORTS // + +export = iterCuNoneBy ; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts new file mode 100644 index 00000000000..35ce594557f --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts @@ -0,0 +1,109 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { TypedIterator, TypedIteratorResult } from '@stdlib/types/iter'; +import iterCuNoneBy = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): TypedIteratorResult { + return { + 'value': 2.0, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): TypedIterator { + return { + 'next': next + }; +} + +/** +* Predicate function. +* +* @param _v - iterated value +* @param i - iteration index +* @returns a boolean +*/ +function predicate1( _v: any, i: number ): boolean { + return ( i > 10 ); +} + +/** +* Predicate function. +* +* @param v - iterated value +* @returns a boolean +*/ +function predicate2( v: any ): boolean { + return ( v !== v ); +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuNoneBy( iterator(), predicate1 ); // $ExpectType Iterator + iterCuNoneBy( iterator(), predicate2 ); // $ExpectType Iterator + iterCuNoneBy( iterator(), predicate1, {} ); // $ExpectType Iterator + iterCuNoneBy( iterator(), predicate2, {} ); // $ExpectType Iterator + iterCuNoneBy( iterator(), predicate1, null ); // $ExpectType Iterator + iterCuNoneBy( iterator(), predicate2, null ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... +{ + iterCuNoneBy( '5', predicate1 ); // $ExpectError + iterCuNoneBy( 5, predicate1 ); // $ExpectError + iterCuNoneBy( true, predicate1 ); // $ExpectError + iterCuNoneBy( false, predicate1 ); // $ExpectError + iterCuNoneBy( null, predicate1 ); // $ExpectError + iterCuNoneBy( undefined, predicate1 ); // $ExpectError + iterCuNoneBy( [], predicate1 ); // $ExpectError + iterCuNoneBy( {}, predicate1 ); // $ExpectError + iterCuNoneBy( ( x: number ): number => x, predicate1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a predicate function... +{ + iterCuNoneBy( iterator(), '5' ); // $ExpectError + iterCuNoneBy( iterator(), 5 ); // $ExpectError + iterCuNoneBy( iterator(), true ); // $ExpectError + iterCuNoneBy( iterator(), false ); // $ExpectError + iterCuNoneBy( iterator(), null ); // $ExpectError + iterCuNoneBy( iterator(), undefined ); // $ExpectError + iterCuNoneBy( iterator(), [] ); // $ExpectError + iterCuNoneBy( iterator(), {} ); // $ExpectError + iterCuNoneBy( iterator(), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuNoneBy(); // $ExpectError + iterCuNoneBy( iterator() ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js new file mode 100644 index 00000000000..60ac7bbf021 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuNoneBy = require( './../lib' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which cumulatively tests whether every iterated value fails a test: +var it = iterCuNoneBy( riter, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js new file mode 100644 index 00000000000..919e73bf62f --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Create an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +* +* @module @stdlib/iter/cuevery-by +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuNoneBy = require( '@stdlib/iter/cuevery-by' ); +* +* 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 +*/ + + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js new file mode 100644 index 00000000000..d93c22dc47c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js @@ -0,0 +1,157 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +* +* @param {Iterator} iterator - input iterator +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an iterator +* @throws {TypeError} second argument must be a predicate function +* @returns {Iterator} iterator +* +* @example +* 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 +*/ +function iterCuNoneBy( iterator, predicate, thisArg ) { + var value; + var iter; + var FLG; + var i; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an iterator. Value: `%s`.', iterator ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); + } + value = true; + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator`, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + if ( value && predicate.call( thisArg, v.value, i ) ) { + value = false; + } + return { + 'value': value, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterCuNoneBy( iterator[ iteratorSymbol ](), predicate, thisArg ); + } +} + + +// EXPORTS // + +module.exports = iterCuNoneBy; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/package.json b/lib/node_modules/@stdlib/iter/cuevery-by/package.json new file mode 100644 index 00000000000..fb6427bcd1c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/iter/cuevery-by", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "none", + "every", + "all", + "cunone", + "iterator", + "iterate", + "iteration", + "iter" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js b/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js new file mode 100644 index 00000000000..5d185d85a96 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js @@ -0,0 +1,364 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var randu = require( '@stdlib/random/iter/randu' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var noop = require( '@stdlib/utils/noop' ); +var iterCuNoneBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value > 0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuNoneBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuNoneBy( value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function as a second argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuNoneBy( array2iterator( [ 1, 2, 3 ] ), value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var arr; + var it; + var r; + var i; + + arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); + it = iterCuNoneBy( arr, predicate ); + for ( i = 0; i < 5; i++ ) { + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an "empty" iterator, the function returns an iterator which is also empty', function test( t ) { + var arr; + var it; + var v; + + arr = array2iterator( [] ); + it = iterCuNoneBy( arr, predicate ); + + v = it.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 0, 0, 1, 1, 0, 0 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuNoneBy( array2iterator( values ), predicate ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterCuNoneBy( randu(), predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterCuNoneBy( randu(), predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'foo' ); + t.equal( r.value, 'foo', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { + var iterCuNoneBy; + var opts; + var rand; + var it1; + var it2; + var i; + + iterCuNoneBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterCuNoneBy( rand, predicate ); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 100; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function factory() { + return randu( opts ); + } +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterCuNoneBy; + var it; + + iterCuNoneBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterCuNoneBy( randu(), predicate); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); + +tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { + var iterCuNoneBy; + var rand; + var it; + + iterCuNoneBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterCuNoneBy( rand, predicate ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); +tape( 'the function supports specifying the predicate function execution context', function test( t ) { + var expected; + var actual; + var values; + var ctx; + var it; + var i; + + ctx = { + 'count': 0 + }; + + values = [ -1, -3, 2, 0, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuNoneBy( array2iterator( values ), predicate, ctx ); + t.equal( it.next.length, 0, 'has zero arity' ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.equal( ctx.count, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); From 7a87e6f6a33894578cfa4dd5937df6aeea6084c8 Mon Sep 17 00:00:00 2001 From: Mohammad Kaif Date: Tue, 27 Aug 2024 15:56:42 +0545 Subject: [PATCH 2/5] feat(iter): add `@stdlib/iter/cuevery-by` package Co-authored-by: Mohammad Kaif Ref: https://github.com/stdlib-js/stdlib/issues/2336 --- .../@stdlib/iter/cuevery-by/README.md | 26 ++++----- .../iter/cuevery-by/benchmark/benchmark.js | 6 +-- .../@stdlib/iter/cuevery-by/docs/repl.txt | 6 +-- .../iter/cuevery-by/docs/types/index.d.ts | 8 +-- .../iter/cuevery-by/docs/types/test.ts | 54 +++++++++---------- .../@stdlib/iter/cuevery-by/examples/index.js | 6 +-- .../@stdlib/iter/cuevery-by/lib/index.js | 8 +-- .../@stdlib/iter/cuevery-by/lib/main.js | 14 ++--- .../@stdlib/iter/cuevery-by/package.json | 4 +- .../@stdlib/iter/cuevery-by/test/test.js | 44 +++++++-------- 10 files changed, 88 insertions(+), 88 deletions(-) diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/README.md b/lib/node_modules/@stdlib/iter/cuevery-by/README.md index 5f7a5601527..3fdcd3f1c0c 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/README.md +++ b/lib/node_modules/@stdlib/iter/cuevery-by/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# iterCuNoneBy +# iterCuEveryBy -> Create an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +> Create an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. @@ -37,12 +37,12 @@ limitations under the License. ## Usage ```javascript -var iterCuNoneBy = require( '@stdlib/iter/cuevery-by' ); +var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); ``` -#### iterCuNoneBy( iterator, predicate\[, thisArg] ) +#### iterCuEveryBy( iterator, predicate\[, thisArg] ) -Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value fails a test implemented by a `predicate` function. +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value passes a test implemented by a `predicate` function. ```javascript var array2iterator = require( '@stdlib/array/to-iterator' ); @@ -51,9 +51,9 @@ function predicate( v ) { return ( v > 0 ); } -var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); +var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); -var it = iterCuNoneBy( arr, predicate ); +var it = iterCuEveryBy( arr, predicate ); var v = it.next().value; // returns true @@ -93,14 +93,14 @@ var array2iterator = require( '@stdlib/array/to-iterator' ); function predicate( v ) { this.count += 1; - return ( v < 0 ); + return ( v > 0 ); } var ctx = { 'count': 0 }; -var it = iterCuNoneBy( array2iterator( [ 1, 2, 3, 4 ] ), predicate, ctx ); +var it = iterCuEveryBy( array2iterator( [ 1, 2, 3, 4 ] ), predicate, ctx ); // returns var v = it.next().value; @@ -129,7 +129,7 @@ var count = ctx.count; ## Notes -- A `predicate` function is invoked for each iterated value until the first truthy `predicate` function return value. Upon encountering the first truthy return value, the returned iterator ceases to invoke the `predicate` function and returns `false` for each subsequent iterated value of the provided input `iterator`. +- A `predicate` function is invoked for each iterated value until the first falsy `predicate` function return value. Upon encountering the first falsy return value, the returned iterator ceases to invoke the `predicate` function and returns `false` for each subsequent iterated value of the provided input `iterator`. @@ -145,7 +145,7 @@ var count = ctx.count; ```javascript var randu = require( '@stdlib/random/iter/randu' ); -var iterCuNoneBy = require( '@stdlib/iter/cuevery-by' ); +var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); function threshold( r ) { return ( r > 0.95 ); @@ -157,8 +157,8 @@ var opts = { }; var riter = randu( opts ); -// Create an iterator which cumulatively tests whether every iterated value fails a test: -var it = iterCuNoneBy( riter, threshold ); +// Create an iterator which cumulatively tests whether every iterated value passes a test: +var it = iterCuEveryBy( riter, threshold ); // Perform manual iteration... var r; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js index 6ab0a50cb2c..14374fbd279 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js @@ -25,7 +25,7 @@ var iterConstant = require( '@stdlib/iter/constant' ); var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; -var iterCuNoneBy = require( './../lib' ); +var iterCuEveryBy = require( './../lib' ); // FUNCTIONS // @@ -53,7 +53,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - iter = iterCuNoneBy( it, predicate ); + iter = iterCuEveryBy( it, predicate ); if ( typeof iter !== 'object' ) { b.fail( 'should return an object' ); } @@ -71,7 +71,7 @@ bench( pkg+'::iteration', function benchmark( b ) { var v; var i; - iter = iterCuNoneBy( iterConstant( 3.14 ), predicate ); + iter = iterCuEveryBy( iterConstant( 3.14 ), predicate ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt index aefc637220f..aa08d09f8a1 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( iterator, predicate[, thisArg] ) Returns an iterator which cumulatively tests whether every iterated value - fails a test implemented by a predicate function. + passes a test implemented by a predicate function. If an environment supports Symbol.iterator and a provided iterator is iterable, the returned iterator is iterable. @@ -12,7 +12,7 @@ - index: iteration index A predicate function is invoked for each iterated value until the first - truthy predicate function return value. Upon encountering the first truthy + falsy predicate function return value. Upon encountering the first falsy return value, the returned iterator ceases to invoke the predicate function and returns `false` for each subsequent iterated value of the provided input iterator. @@ -46,7 +46,7 @@ Examples -------- - > var arr = {{alias:@stdlib/array/to-iterator}}( [ 0, 0, 0, 1, 0 ] ); + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 1, 1, 1, 0, 1 ] ); > function fcn( v ) { return ( v > 0 ); }; > var it = {{alias}}( arr, fcn ); > var v = it.next().value diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts index 30635bf1326..6ce2f46f3ae 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts @@ -59,7 +59,7 @@ type Binary = ( this: U, value: T, index: number ) => boolean; type Predicate = Nullary | Unary | Binary; /** -* Returns an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +* Returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. * * @param iterator - source iterator * @param predicate - predicate function @@ -72,7 +72,7 @@ type Predicate = Nullary | Unary | Binary; * return ( v > 0 ); * } * -* var it = iterCuNoneBy( array2iterator( [ 0, 0, 0, 1, 0 ] ), isPositive ); +* var it = iterCuEveryBy( array2iterator( [ 1, 1, 1, 0, 1 ] ), isPositive ); * * var v = it.next().value; * // returns true @@ -89,9 +89,9 @@ type Predicate = Nullary | Unary | Binary; * v = it.next().value; * // returns false */ -declare function iterCuNoneBy( iterator: Iterator, predicate: Predicate, thisArg?: ThisParameterType> ): Iterator; +declare function iterCuEveryBy( iterator: Iterator, predicate: Predicate, thisArg?: ThisParameterType> ): Iterator; // EXPORTS // -export = iterCuNoneBy ; +export = iterCuEveryBy ; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts index 35ce594557f..d756e029c94 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts @@ -17,7 +17,7 @@ */ import { TypedIterator, TypedIteratorResult } from '@stdlib/types/iter'; -import iterCuNoneBy = require( './index' ); +import iterCuEveryBy = require( './index' ); /** * Implements the iterator protocol `next` method. @@ -68,42 +68,42 @@ function predicate2( v: any ): boolean { // The function returns an iterator... { - iterCuNoneBy( iterator(), predicate1 ); // $ExpectType Iterator - iterCuNoneBy( iterator(), predicate2 ); // $ExpectType Iterator - iterCuNoneBy( iterator(), predicate1, {} ); // $ExpectType Iterator - iterCuNoneBy( iterator(), predicate2, {} ); // $ExpectType Iterator - iterCuNoneBy( iterator(), predicate1, null ); // $ExpectType Iterator - iterCuNoneBy( iterator(), predicate2, null ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate1 ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate2 ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate1, {} ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate2, {} ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate1, null ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate2, null ); // $ExpectType Iterator } // The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... { - iterCuNoneBy( '5', predicate1 ); // $ExpectError - iterCuNoneBy( 5, predicate1 ); // $ExpectError - iterCuNoneBy( true, predicate1 ); // $ExpectError - iterCuNoneBy( false, predicate1 ); // $ExpectError - iterCuNoneBy( null, predicate1 ); // $ExpectError - iterCuNoneBy( undefined, predicate1 ); // $ExpectError - iterCuNoneBy( [], predicate1 ); // $ExpectError - iterCuNoneBy( {}, predicate1 ); // $ExpectError - iterCuNoneBy( ( x: number ): number => x, predicate1 ); // $ExpectError + iterCuEveryBy( '5', predicate1 ); // $ExpectError + iterCuEveryBy( 5, predicate1 ); // $ExpectError + iterCuEveryBy( true, predicate1 ); // $ExpectError + iterCuEveryBy( false, predicate1 ); // $ExpectError + iterCuEveryBy( null, predicate1 ); // $ExpectError + iterCuEveryBy( undefined, predicate1 ); // $ExpectError + iterCuEveryBy( [], predicate1 ); // $ExpectError + iterCuEveryBy( {}, predicate1 ); // $ExpectError + iterCuEveryBy( ( x: number ): number => x, predicate1 ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a predicate function... { - iterCuNoneBy( iterator(), '5' ); // $ExpectError - iterCuNoneBy( iterator(), 5 ); // $ExpectError - iterCuNoneBy( iterator(), true ); // $ExpectError - iterCuNoneBy( iterator(), false ); // $ExpectError - iterCuNoneBy( iterator(), null ); // $ExpectError - iterCuNoneBy( iterator(), undefined ); // $ExpectError - iterCuNoneBy( iterator(), [] ); // $ExpectError - iterCuNoneBy( iterator(), {} ); // $ExpectError - iterCuNoneBy( iterator(), ( x: number ): number => x ); // $ExpectError + iterCuEveryBy( iterator(), '5' ); // $ExpectError + iterCuEveryBy( iterator(), 5 ); // $ExpectError + iterCuEveryBy( iterator(), true ); // $ExpectError + iterCuEveryBy( iterator(), false ); // $ExpectError + iterCuEveryBy( iterator(), null ); // $ExpectError + iterCuEveryBy( iterator(), undefined ); // $ExpectError + iterCuEveryBy( iterator(), [] ); // $ExpectError + iterCuEveryBy( iterator(), {} ); // $ExpectError + iterCuEveryBy( iterator(), ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments... { - iterCuNoneBy(); // $ExpectError - iterCuNoneBy( iterator() ); // $ExpectError + iterCuEveryBy(); // $ExpectError + iterCuEveryBy( iterator() ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js index 60ac7bbf021..fad12f73e05 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js @@ -19,7 +19,7 @@ 'use strict'; var randu = require( '@stdlib/random/iter/randu' ); -var iterCuNoneBy = require( './../lib' ); +var iterCuEveryBy = require( './../lib' ); function threshold( r ) { return ( r > 0.95 ); @@ -31,8 +31,8 @@ var opts = { }; var riter = randu( opts ); -// Create an iterator which cumulatively tests whether every iterated value fails a test: -var it = iterCuNoneBy( riter, threshold ); +// Create an iterator which cumulatively tests whether every iterated value passes a test: +var it = iterCuEveryBy( riter, threshold ); // Perform manual iteration... var r; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js index 919e73bf62f..83db4b7e121 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js @@ -19,21 +19,21 @@ 'use strict'; /** -* Create an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +* Create an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. * * @module @stdlib/iter/cuevery-by * * @example * var array2iterator = require( '@stdlib/array/to-iterator' ); -* var iterCuNoneBy = require( '@stdlib/iter/cuevery-by' ); +* var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); * * function isPositive( value ) { * return ( value > 0 ); * } * -* var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); +* var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); * -* var it = iterCuNoneBy( arr, isPositive ); +* var it = iterCuEveryBy( arr, isPositive ); * * var v = it.next().value; * // returns true diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js index d93c22dc47c..79d08891a3c 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js @@ -30,7 +30,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function. +* Returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. * * @param {Iterator} iterator - input iterator * @param {Function} predicate - predicate function @@ -46,9 +46,9 @@ var format = require( '@stdlib/string/format' ); * return ( value > 0 ); * } * -* var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); +* var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); * -* var it = iterCuNoneBy( arr, isPositive ); +* var it = iterCuEveryBy( arr, isPositive ); * * var v = it.next().value; * // returns true @@ -68,7 +68,7 @@ var format = require( '@stdlib/string/format' ); * var bool = it.next().done; * // returns true */ -function iterCuNoneBy( iterator, predicate, thisArg ) { +function iterCuEveryBy( iterator, predicate, thisArg ) { var value; var iter; var FLG; @@ -111,7 +111,7 @@ function iterCuNoneBy( iterator, predicate, thisArg ) { FLG = true; return v; } - if ( value && predicate.call( thisArg, v.value, i ) ) { + if ( value && !predicate.call( thisArg, v.value, i ) ) { value = false; } return { @@ -147,11 +147,11 @@ function iterCuNoneBy( iterator, predicate, thisArg ) { * @returns {Iterator} iterator */ function factory() { - return iterCuNoneBy( iterator[ iteratorSymbol ](), predicate, thisArg ); + return iterCuEveryBy( iterator[ iteratorSymbol ](), predicate, thisArg ); } } // EXPORTS // -module.exports = iterCuNoneBy; +module.exports = iterCuEveryBy; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/package.json b/lib/node_modules/@stdlib/iter/cuevery-by/package.json index fb6427bcd1c..4aef4d53cae 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/package.json +++ b/lib/node_modules/@stdlib/iter/cuevery-by/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/iter/cuevery-by", "version": "0.0.0", - "description": "Create an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function.", + "description": "Create an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -59,7 +59,7 @@ "none", "every", "all", - "cunone", + "cuevery", "iterator", "iterate", "iteration", diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js b/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js index 5d185d85a96..7b0ae0c7cc6 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js @@ -26,7 +26,7 @@ var array2iterator = require( '@stdlib/array/to-iterator' ); var randu = require( '@stdlib/random/iter/randu' ); var iteratorSymbol = require( '@stdlib/symbol/iterator' ); var noop = require( '@stdlib/utils/noop' ); -var iterCuNoneBy = require( './../lib' ); +var iterCuEveryBy = require( './../lib' ); // FUNCTIONS // @@ -47,7 +47,7 @@ function predicate( value ) { tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof iterCuNoneBy, 'function', 'main export is a function' ); + t.strictEqual( typeof iterCuEveryBy, 'function', 'main export is a function' ); t.end(); }); @@ -75,7 +75,7 @@ tape( 'the function throws an error if not provided an iterator', function test( function badValue( value ) { return function badValue() { - iterCuNoneBy( value, noop ); + iterCuEveryBy( value, noop ); }; } }); @@ -105,7 +105,7 @@ tape( 'the function throws an error if not provided a predicate function as a se function badValue( value ) { return function badValue() { - iterCuNoneBy( array2iterator( [ 1, 2, 3 ] ), value ); + iterCuEveryBy( array2iterator( [ 1, 2, 3 ] ), value ); }; } }); @@ -117,7 +117,7 @@ tape( 'the function returns an iterator protocol-compliant object', function tes var i; arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); - it = iterCuNoneBy( arr, predicate ); + it = iterCuEveryBy( arr, predicate ); for ( i = 0; i < 5; i++ ) { r = it.next(); t.equal( typeof r.value, 'boolean', 'returns expected value' ); @@ -133,7 +133,7 @@ tape( 'if provided an "empty" iterator, the function returns an iterator which i var v; arr = array2iterator( [] ); - it = iterCuNoneBy( arr, predicate ); + it = iterCuEveryBy( arr, predicate ); v = it.next(); t.strictEqual( v.done, true, 'returns expected value' ); @@ -141,14 +141,14 @@ tape( 'if provided an "empty" iterator, the function returns an iterator which i t.end(); }); -tape( 'the function returns an iterator which cumulatively tests whether every iterated value fails a test implemented by a predicate function', function test( t ) { +tape( 'the function returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function', function test( t ) { var expected; var actual; var values; var it; var i; - values = [ 0, 0, 1, 1, 0, 0 ]; + values = [ 1, 1, 0, 0, 0, 0 ]; expected = [ { 'value': true, @@ -179,7 +179,7 @@ tape( 'the function returns an iterator which cumulatively tests whether every i } ]; - it = iterCuNoneBy( array2iterator( values ), predicate ); + it = iterCuEveryBy( array2iterator( values ), predicate ); actual = []; for ( i = 0; i < expected.length; i++ ) { @@ -193,7 +193,7 @@ tape( 'the returned iterator has a `return` method for closing an iterator (no a var it; var r; - it = iterCuNoneBy( randu(), predicate ); + it = iterCuEveryBy( randu(), predicate ); r = it.next(); t.equal( typeof r.value, 'boolean', 'returns expected value' ); @@ -218,7 +218,7 @@ tape( 'the returned iterator has a `return` method for closing an iterator (argu var it; var r; - it = iterCuNoneBy( randu(), predicate ); + it = iterCuEveryBy( randu(), predicate ); r = it.next(); t.equal( typeof r.value, 'boolean', 'returns expected value' ); @@ -240,14 +240,14 @@ tape( 'the returned iterator has a `return` method for closing an iterator (argu }); tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { - var iterCuNoneBy; + var iterCuEveryBy; var opts; var rand; var it1; var it2; var i; - iterCuNoneBy = proxyquire( './../lib/main.js', { + iterCuEveryBy = proxyquire( './../lib/main.js', { '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' }); @@ -257,7 +257,7 @@ tape( 'if an environment supports `Symbol.iterator` and the provided iterator is rand = randu( opts ); rand[ '__ITERATOR_SYMBOL__' ] = factory; - it1 = iterCuNoneBy( rand, predicate ); + it1 = iterCuEveryBy( rand, predicate ); t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); @@ -277,32 +277,32 @@ tape( 'if an environment supports `Symbol.iterator` and the provided iterator is }); tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var iterCuNoneBy; + var iterCuEveryBy; var it; - iterCuNoneBy = proxyquire( './../lib/main.js', { + iterCuEveryBy = proxyquire( './../lib/main.js', { '@stdlib/symbol/iterator': false }); - it = iterCuNoneBy( randu(), predicate); + it = iterCuEveryBy( randu(), predicate); t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); t.end(); }); tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { - var iterCuNoneBy; + var iterCuEveryBy; var rand; var it; - iterCuNoneBy = proxyquire( './../lib/main.js', { + iterCuEveryBy = proxyquire( './../lib/main.js', { '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' }); rand = randu(); rand[ '__ITERATOR_SYMBOL__' ] = null; - it = iterCuNoneBy( rand, predicate ); + it = iterCuEveryBy( rand, predicate ); t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); t.end(); @@ -319,7 +319,7 @@ tape( 'the function supports specifying the predicate function execution context 'count': 0 }; - values = [ -1, -3, 2, 0, 1 ]; + values = [ 1, 3, -2, 0, 1 ]; expected = [ { 'value': true, @@ -346,7 +346,7 @@ tape( 'the function supports specifying the predicate function execution context } ]; - it = iterCuNoneBy( array2iterator( values ), predicate, ctx ); + it = iterCuEveryBy( array2iterator( values ), predicate, ctx ); t.equal( it.next.length, 0, 'has zero arity' ); actual = []; From 1a6bfac11d17e6e8450f9633f55a07cc4cc4ecfd Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 8 Oct 2024 20:38:09 -0400 Subject: [PATCH 3/5] chore: minor clean-up --- lib/node_modules/@stdlib/iter/cuevery-by/README.md | 2 +- .../@stdlib/iter/cuevery-by/benchmark/benchmark.js | 2 +- lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt | 4 ++-- lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/README.md b/lib/node_modules/@stdlib/iter/cuevery-by/README.md index 3fdcd3f1c0c..4cf25c970db 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/README.md +++ b/lib/node_modules/@stdlib/iter/cuevery-by/README.md @@ -148,7 +148,7 @@ var randu = require( '@stdlib/random/iter/randu' ); var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); function threshold( r ) { - return ( r > 0.95 ); + return ( r > 0.05 ); } // Create an iterator which generates uniformly distributed pseudorandom numbers: diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js index 14374fbd279..63a4037b3de 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js @@ -38,7 +38,7 @@ var iterCuEveryBy = require( './../lib' ); * @returns {boolean} result */ function predicate( value ) { - return ( value < 0 ); + return ( value > 0 ); } diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt index aa08d09f8a1..34f203364bf 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt @@ -38,8 +38,8 @@ iterator.next(): Function Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating - whether the iterator is finished. + iterated value (if one exists) and a boolean flag indicating whether the + iterator is finished. iterator.return( [value] ): Function Finishes an iterator and returns a provided value. diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js index fad12f73e05..ccc710f03ac 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js @@ -22,7 +22,7 @@ var randu = require( '@stdlib/random/iter/randu' ); var iterCuEveryBy = require( './../lib' ); function threshold( r ) { - return ( r > 0.95 ); + return ( r > 0.05 ); } // Create an iterator which generates uniformly distributed pseudorandom numbers: From a982712ef4b3f1b1bfca17b984b839a37f8ae258 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 8 Oct 2024 20:38:39 -0400 Subject: [PATCH 4/5] fix: correctly increment index --- lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js index 79d08891a3c..56a68824e91 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js @@ -111,6 +111,7 @@ function iterCuEveryBy( iterator, predicate, thisArg ) { FLG = true; return v; } + i += 1; if ( value && !predicate.call( thisArg, v.value, i ) ) { value = false; } From 19d1abb4f0144aa67b08df82b741b5954a8cad1c Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 8 Oct 2024 20:43:59 -0400 Subject: [PATCH 5/5] docs: add missing parameter description Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts index 6ce2f46f3ae..34b5672200c 100644 --- a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts @@ -63,6 +63,7 @@ type Predicate = Nullary | Unary | Binary; * * @param iterator - source iterator * @param predicate - predicate function +* @param thisArg - execution context * @returns iterator * * @example