Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add iter/cuany #2440

Merged
merged 41 commits into from
Jun 25, 2024
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0f2c4d6
Added @stdlib/math/base/special/nanmin
Jun 8, 2024
d144bb4
Added @stdlib/math/base/special/nanmin
Jun 9, 2024
78d82a3
Added @stdlib/math/base/special/nanmin
Jun 9, 2024
cf88b61
Added @stdlib/math/base/special/nanmin
Jun 9, 2024
4a1e103
Added @stdlib/math/base/special/nanmin
Jun 9, 2024
aeb3795
Added @stdlib/math/base/special/nanmin
Jun 9, 2024
4ff14fc
Added @stdlib/math/base/special/nanmin
Jun 9, 2024
b1edc3d
feat: added @stdlib/math/base/special/nanmin
Jun 9, 2024
6460912
feat: added @stdlib/math/base/special/nanmin
Jun 9, 2024
5ccd941
chore: update copyright years
stdlib-bot Jun 9, 2024
4a4f8f3
feat: added @stdlib/math/base/special/nanmin
Jun 10, 2024
39e88db
Merge branch 'main' of https://github.com/RidamGarg/stdlib
Jun 10, 2024
4a8425e
feat: added @stdlib/math/base/special/nanmin
RidamGarg Jun 10, 2024
0118ae0
Update lib/node_modules/@stdlib/math/base/special/nanmin/lib/main.js
Planeshifter Jun 10, 2024
ebbc316
feat: add @stdlib/math/base/special/nanmax
Jun 11, 2024
b66ba8e
feat: add math/base/special/nanmax
RidamGarg Jun 11, 2024
169c767
feat: add math/base/special/nanmax
RidamGarg Jun 11, 2024
2ad1323
feat: add math/base/special/nanmax
RidamGarg Jun 11, 2024
876732a
Merge branch 'develop' into main
RidamGarg Jun 11, 2024
79ffdf9
feat: add @stdlib/math/base/special/nanmax
RidamGarg Jun 11, 2024
c0728d7
Merge branch 'develop' into main
Planeshifter Jun 12, 2024
43d5904
chore: minor clean-up
Planeshifter Jun 12, 2024
2eab29d
chore: update line endings
Planeshifter Jun 12, 2024
544fed9
chore: update README.md
Planeshifter Jun 12, 2024
204a7b6
chore: update line endings in repl.txt
Planeshifter Jun 12, 2024
87567d2
feat: add @stdlib/iter/cuany
Jun 23, 2024
7c1ff01
feat: add @stdlib/iter/cuany
Jun 23, 2024
c5f61a4
feat: add @stdlib/iter/cuany
Jun 23, 2024
c1086d4
feat: add @stdlib/iter/cuany
Jun 23, 2024
9b39111
feat: add @stdlib/iter/cuany
RidamGarg Jun 23, 2024
b236648
feat: add @stdlib/iter/cuany
RidamGarg Jun 23, 2024
3807059
Merge branch 'develop' into main
RidamGarg Jun 23, 2024
957fb99
bench: refactor to use existing utilities
kgryte Jun 24, 2024
4d681fe
docs: update copyright years and address lint errors
kgryte Jun 24, 2024
cbd728b
docs: fix declarations
kgryte Jun 24, 2024
eda9711
docs: update example
kgryte Jun 24, 2024
fdceb97
refactor: fix implementation to lazily consume upstream values
kgryte Jun 24, 2024
297ad02
test: add additional tests
kgryte Jun 24, 2024
758fc63
docs: update description
kgryte Jun 24, 2024
db0a54c
docs: undo linebreak changes
kgryte Jun 25, 2024
d7d4a3b
chore: delete stray file
kgryte Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!--

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

-->

# iterCuAny

> Create an [iterator][mdn-iterator-protocol] which cumulatively tests whether at least one iterated value is truthy.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var iterCuAny = require( '@stdlib/iter/cuany' );
```

#### iterCuAny( iterator )

Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether at least one iterated value is truthy.

```javascript
var array2iterator = require( '@stdlib/array/to-iterator' );

var arr = array2iterator( [ 0, 0, 0, 1, 0 ] );

var it = iterCuAny( arr );
// returns <Object>

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

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

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

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

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

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.

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/iter/randu' );
var iterMap = require( '@stdlib/iter/map' );
var iterCuAny = require( '@stdlib/iter/cuany' );

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 applies a threshold to generated numbers:
var miter = iterMap( riter, threshold );

// Create an iterator which cumulatively tests whether at least one iterated value is truthy:
var it = iterCuAny( miter );

// Perform manual iteration...
var r;
while ( true ) {
r = it.next();
if ( r.done ) {
break;
}
console.log( r.value );
}
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol

</section>

<!-- /.links -->
75 changes: 75 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var iterCuAny = 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 = iterCuAny( 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 = iterCuAny( iterConstant( 3.14 ) );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = iter.next().value;
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

{{alias}}( iterator )
Returns an iterator which cumulatively tests whether at least one 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}}( [ 0, 0, 0, 1, 0 ] );
> var it = {{alias}}( arr );
> var v = it.next().value
false
> v = it.next().value
false
> v = it.next().value
false
> v = it.next().value
true
> v = it.next().value
true

See Also
--------

64 changes: 64 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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

/// <reference types="@stdlib/types"/>

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 at least one iterated value is truthy.
*
* @param iterator - input iterator
* @returns iterator
*
* @example
* var array2iterator = require( '@stdlib/array/to-iterator' );
*
* var arr = array2iterator( [ false, false, false, true, false ] );
*
* var it = iterCuAny( arr );
*
* var v = it.next().value;
* returns false
*
* v = it.next().value;
* returns false
*
* v = it.next().value;
* returns false
*
* v = it.next().value;
* returns true
*
* v = it.next().value;
* returns true
*
* var bool = it.next().done;
* returns true
*/
declare function iterCuAny( iterator: Iterator ): Iterator;


// EXPORTS //

export = iterCuAny;
69 changes: 69 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/docs/types/test.ts
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/examples/index.js
60 changes: 60 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/lib/index.js
145 changes: 145 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/lib/main.js
66 changes: 66 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/package.json
322 changes: 322 additions & 0 deletions lib/node_modules/@stdlib/iter/cuany/test/test.js