Skip to content

Commit 4dac1d5

Browse files
committed
Fix description, fix missing fields, and add type declarations
1 parent e7ed98d commit 4dac1d5

File tree

6 files changed

+148
-1
lines changed

6 files changed

+148
-1
lines changed

lib/node_modules/@stdlib/iter/every/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

lib/node_modules/@stdlib/iter/none/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
interface Iterator {
22+
/**
23+
* Returns an iterator protocol-compliant object containing the next iterated value (if one exists) and a boolean flag indicating whether the iterator is finished.
24+
*
25+
* @returns iterator protocol-compliant object
26+
*/
27+
next(): IteratorResult;
28+
}
29+
30+
interface IteratorResult {
31+
/**
32+
* Iterated value (if one exists).
33+
*/
34+
value?: any;
35+
36+
/**
37+
* Boolean flag indicating whether the iterator is finished.
38+
*/
39+
done: boolean;
40+
}
41+
42+
/**
43+
* Tests whether at least `n` iterated values are truthy.
44+
*
45+
* @param iterator - input iterator
46+
* @throws second argument must be a positive integer
47+
* @returns boolean indicating whether at least `n` iterated values are truthy
48+
*
49+
* @example
50+
*
51+
* var array2iterator = require( '@stdlib/array/to-iterator' );
52+
*
53+
* var it = array2iterator( [ 0, 0, 1, 1, 1 ] );
54+
*
55+
* var bool = iterSome( it, 3 );
56+
* // returns true
57+
*/
58+
declare function iterSome( iterator: Iterator, n: number ): boolean;
59+
60+
61+
// EXPORTS //
62+
63+
export = iterSome;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import iterSome = require( './index' );
20+
21+
/**
22+
* Returns an iterator protocol-compliant object.
23+
*
24+
* @returns iterator protocol-compliant object
25+
*/
26+
function iterator() {
27+
return {
28+
'next': next
29+
};
30+
31+
/**
32+
* Implements the iterator protocol `next` method.
33+
*
34+
* @returns iterator protocol-compliant object
35+
*/
36+
function next() {
37+
return {
38+
'value': true,
39+
'done': false
40+
};
41+
}
42+
}
43+
44+
45+
// TESTS //
46+
47+
// The function returns a boolean...
48+
{
49+
iterSome( iterator(), 3 ); // $ExpectType boolean
50+
}
51+
52+
// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object...
53+
{
54+
iterSome( '5', 3 ); // $ExpectError
55+
iterSome( 5, 3 ); // $ExpectError
56+
iterSome( true, 3 ); // $ExpectError
57+
iterSome( false, 3 ); // $ExpectError
58+
iterSome( null, 3 ); // $ExpectError
59+
iterSome( undefined, 3 ); // $ExpectError
60+
iterSome( [], 3 ); // $ExpectError
61+
iterSome( {}, 3 ); // $ExpectError
62+
iterSome( ( x ) => x, 3 ); // $ExpectError
63+
}
64+
65+
// The compiler throws an error if the function is provided a second argument which is not a number...
66+
{
67+
iterSome( iterator(), '5' ); // $ExpectError
68+
iterSome( iterator(), true ); // $ExpectError
69+
iterSome( iterator(), false ); // $ExpectError
70+
iterSome( iterator(), null ); // $ExpectError
71+
iterSome( iterator(), undefined ); // $ExpectError
72+
iterSome( iterator(), [] ); // $ExpectError
73+
iterSome( iterator(), {} ); // $ExpectError
74+
iterSome( iterator(), ( x ) => x ); // $ExpectError
75+
}
76+
77+
// The compiler throws an error if the function is provided insufficient arguments...
78+
{
79+
iterSome(); // $ExpectError
80+
iterSome( iterator() ); // $ExpectError
81+
}

lib/node_modules/@stdlib/iter/some/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimit
2727
// MAIN //
2828

2929
/**
30-
* Tests whether at least one iterated value is truthy.
30+
* Tests whether at least `n` iterated values are truthy.
3131
*
3232
* @param {Iterator} iterator - input iterator
3333
* @param {PositiveInteger} n - number of elements

lib/node_modules/@stdlib/iter/some/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)