Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 13, 2024
1 parent a02503c commit c3fcfc9
Show file tree
Hide file tree
Showing 14 changed files with 1,674 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ This release closes the following issue:

##### Features

- [`ce3ad9a`](https://github.com/stdlib-js/stdlib/commit/ce3ad9a98468829b294708ca188ec669056e58ed) - add `keys`, `values`, and `with` methods to `array/bool` [(#2590)](https://github.com/stdlib-js/stdlib/pull/2590)
- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557)
- [`4a6be43`](https://github.com/stdlib-js/stdlib/commit/4a6be430830868fb181bfa0b8923f37dabaffe8a) - add `reduce` and `reduceRight` methods to `array/bool` [(#2509)](https://github.com/stdlib-js/stdlib/pull/2509)
- [`29615af`](https://github.com/stdlib-js/stdlib/commit/29615af970796a43f65f4b00d29bd23a122f2208) - add `slice` and `subarray` methods to `array/bool` [(#2472)](https://github.com/stdlib-js/stdlib/pull/2472)
Expand Down Expand Up @@ -2435,6 +2436,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`ce3ad9a`](https://github.com/stdlib-js/stdlib/commit/ce3ad9a98468829b294708ca188ec669056e58ed) - **feat:** add `keys`, `values`, and `with` methods to `array/bool` [(#2590)](https://github.com/stdlib-js/stdlib/pull/2590) _(by Jaysukh Makvana)_
- [`2cf1a24`](https://github.com/stdlib-js/stdlib/commit/2cf1a248120648c46ca4e5bd6535c62a6f3eba6e) - **docs:** update namespace TypeScript declarations [(#2582)](https://github.com/stdlib-js/stdlib/pull/2582) _(by stdlib-bot, Athan Reines)_
- [`66dce03`](https://github.com/stdlib-js/stdlib/commit/66dce034698fdbd71248cad9c7d277ac97cdf0ae) - **feat:** add boolean dtype support to `array/min-dtype` [(#2556)](https://github.com/stdlib-js/stdlib/pull/2556) _(by Jaysukh Makvana, Athan Reines)_
- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - **feat:** add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557) _(by Jaysukh Makvana, Athan Reines)_
Expand Down
80 changes: 80 additions & 0 deletions bool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,35 @@ var str = arr.join( '|' );
// returns 'true|false|true'
```

<a name="method-keys"></a>

#### BooleanArray.prototype.keys()

Returns an iterator for iterating over each index key in a typed array.

```javascript
var arr = new BooleanArray( 2 );

arr.set( true, 0 );
arr.set( false, 1 );

var iter = arr.keys();

var v = iter.next().value;
// returns 0

v = iter.next().value;
// returns 1

var bool = iter.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 name="method-last-index-of"></a>

#### BooleanArray.prototype.lastIndexOf( searchElement\[, fromIndex] )
Expand Down Expand Up @@ -1337,6 +1366,55 @@ var str = arr.toString();
// returns 'true,false,true'
```

<a name="method-values"></a>

#### BooleanArray.prototype.values()

Returns an iterator for iterating over each value in a typed array.

```javascript
var arr = new BooleanArray( 2 );

arr.set( true, 0 );
arr.set( false, 1 );

var iter = arr.values();

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

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

var bool = iter.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 name="method-with"></a>

#### BooleanArray.prototype.with( index, value )

Returns a new typed array with the element at a provided index replaced with a provided value.

```javascript
var arr = new BooleanArray( 3 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( true, 1 );

var out = arr.with( 0, false );
// returns <BooleanArray>

var v = out.get( 0 );
// returns false
```

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -1419,6 +1497,8 @@ console.log( '%s', false );

<section class="links">

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

[@stdlib/array/typed]: https://github.com/stdlib-js/array/tree/main/typed

[@stdlib/array/buffer]: https://github.com/stdlib-js/array/tree/main/buffer
Expand Down
51 changes: 51 additions & 0 deletions bool/benchmark/benchmark.keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @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 isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// MAIN //

bench( pkg+':keys', function benchmark( b ) {
var iter;
var arr;
var i;

arr = new BooleanArray( [ true, false ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.keys();
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();
});
102 changes: 102 additions & 0 deletions bool/benchmark/benchmark.keys.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @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 pow = require( '@stdlib/math/base/special/pow' );
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;
var i;

arr = [];
for ( i = 0; i < len; i++ ) {
arr.push( true );
}
arr = new BooleanArray( arr );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var iter;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.keys();
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();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':keys:len='+len, f );
}
}

main();
51 changes: 51 additions & 0 deletions bool/benchmark/benchmark.values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @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 isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
var pkg = require( './../package.json' ).name;
var BooleanArray = require('./../lib');


// MAIN //

bench( pkg+':values', function benchmark( b ) {
var iter;
var arr;
var i;

arr = new BooleanArray( [ true, false ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.values();
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();
});
Loading

0 comments on commit c3fcfc9

Please sign in to comment.