diff --git a/lib/node_modules/@stdlib/iter/cuevery/README.md b/lib/node_modules/@stdlib/iter/cuevery/README.md new file mode 100644 index 00000000000..65ce2dc0d87 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/README.md @@ -0,0 +1,159 @@ + + +# iterCuEvery + +> Create an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is truthy. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuEvery = require( '@stdlib/iter/cuevery' ); +``` + +#### iterCuEvery( iterator ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is truthy. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); + +var it = iterCuEvery( arr ); +// 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 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. + + + + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterMap = require( '@stdlib/iter/map' ); +var iterCuEvery = require( '@stdlib/iter/cuevery' ); + +function threshold( r ) { + return ( r > 0.1 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which applies a threshold to generated numbers: +var miter = iterMap( riter, threshold ); + +// Create an iterator which cumulatively tests whether every iterated value is truthy: +var it = iterCuEvery( miter ); + +// 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/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuevery/benchmark/benchmark.js new file mode 100644 index 00000000000..35343b2cc42 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/benchmark/benchmark.js @@ -0,0 +1,75 @@ +/** +* @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 iterCuEvery = require( './../lib' ); + + +// 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 = iterCuEvery( it ); + 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 = iterCuEvery( iterConstant( 3.14 ) ); + + 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/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuevery/docs/repl.txt new file mode 100644 index 00000000000..68af81a19c7 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( iterator ) + Returns an iterator which cumulatively tests whether every iterated value is + truthy. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + Parameters + ---------- + iterator: Object + Input iterator. + + 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}}( [ 1, 1, 1, 0, 1 ] ); + > var it = {{alias}}( arr ); + > 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/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuevery/docs/types/index.d.ts new file mode 100644 index 00000000000..202ab2a41c7 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @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 { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Returns an iterator which cumulatively tests whether every iterated value is truthy. +* +* @param iterator - input iterator +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* var arr = array2iterator( [ true, true, true, false, true ] ); +* +* var it = iterCuEvery( arr ); +* +* 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 +*/ +declare function iterCuEvery( iterator: Iterator ): Iterator; + + +// EXPORTS // + +export = iterCuEvery; diff --git a/lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts new file mode 100644 index 00000000000..297181ab950 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @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 { Iterator, IteratorResult } from '@stdlib/types/iter'; +import iterCuEvery = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): IteratorResult { + return { + 'value': true, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): Iterator { + return { + 'next': next + }; +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuEvery( iterator() ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a value other than an iterator protocol-compliant object... +{ + iterCuEvery( '5' ); // $ExpectError + iterCuEvery( 5 ); // $ExpectError + iterCuEvery( true ); // $ExpectError + iterCuEvery( false ); // $ExpectError + iterCuEvery( null ); // $ExpectError + iterCuEvery( undefined ); // $ExpectError + iterCuEvery( [] ); // $ExpectError + iterCuEvery( {} ); // $ExpectError + iterCuEvery( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuEvery(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cuevery/examples/index.js b/lib/node_modules/@stdlib/iter/cuevery/examples/index.js new file mode 100644 index 00000000000..aa23bb62973 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/examples/index.js @@ -0,0 +1,49 @@ +/** +* @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 iterMap = require( '@stdlib/iter/map' ); +var iterCuEvery = require( './../lib' ); + +function threshold( r ) { + return ( r > 0.1 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which applies a threshold to generated numbers: +var miter = iterMap( riter, threshold ); + +// Create an iterator which cumulatively tests whether every iterated value is truthy: +var it = iterCuEvery( miter ); + +// 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/lib/index.js b/lib/node_modules/@stdlib/iter/cuevery/lib/index.js new file mode 100644 index 00000000000..cca0d28e523 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/lib/index.js @@ -0,0 +1,60 @@ +/** +* @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 is truthy. +* +* @module @stdlib/iter/cuevery +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuEvery = require( '@stdlib/iter/cuevery' ); +* +* var arr = array2iterator( [ true, true, false, true, false ] ); +* +* var it = iterCuEvery( arr ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* 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/lib/main.js b/lib/node_modules/@stdlib/iter/cuevery/lib/main.js new file mode 100644 index 00000000000..37f000d2ebb --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/lib/main.js @@ -0,0 +1,145 @@ +/** +* @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 is truthy. +* +* @param {Iterator} iterator - input iterator +* @throws {TypeError} first argument must be an iterator +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* var arr = array2iterator( [ 1, 1, 0, 1, 0 ] ); +* +* var it = iterCuEvery( arr ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ +function iterCuEvery( iterator ) { + var value; + var iter; + var FLG; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. Must provide an iterator. Value: `%s`.', iterator ) ); + } + value = true; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator` and the provided iterator is iterable, 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 ( !v.value ) { + 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 iterCuEvery( iterator[ iteratorSymbol ]() ); + } +} + + +// EXPORTS // + +module.exports = iterCuEvery; diff --git a/lib/node_modules/@stdlib/iter/cuevery/package.json b/lib/node_modules/@stdlib/iter/cuevery/package.json new file mode 100644 index 00000000000..0966ca87f90 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/iter/cuevery", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether every iterated value is truthy.", + "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", + "test", + "every", + "iterate", + "iterator", + "iter", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cuevery/test/test.js b/lib/node_modules/@stdlib/iter/cuevery/test/test.js new file mode 100644 index 00000000000..fd18bf673f8 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/test/test.js @@ -0,0 +1,322 @@ +/** +* @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 iterCuEvery = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuEvery, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator protocol-compliant object', 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() { + iterCuEvery( 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 = iterCuEvery( arr ); + 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 no upstream iterator values are falsy, the function returns an iterator protocol-compliant object which returns all truthy values', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 1, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEvery( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if at least one upstream iterator value is falsy, the function returns an iterator protocol-compliant object which returns falsy values upon encountering the first falsy value', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 0, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEvery( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if all upstream iterator values are truthy, the function returns an iterator protocol-compliant object which always returns truthy values', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 1, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEvery( array2iterator( values ) ); + + 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 = iterCuEvery( randu() ); + + 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 = iterCuEvery( randu() ); + + 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( 'finished' ); + t.equal( r.value, 'finished', '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 iterCuEvery; + var opts; + var rand; + var it1; + var it2; + var i; + + iterCuEvery = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterCuEvery( rand ); + 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 iterCuEvery; + var it; + + iterCuEvery = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterCuEvery( randu() ); + 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 iterCuEvery; + var rand; + var it; + + iterCuEvery = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterCuEvery( rand ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +});