Skip to content

Commit b530017

Browse files
committed
Use overloads to describe predicate function
1 parent b39f169 commit b530017

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

lib/node_modules/@stdlib/iter/reject/docs/types/index.d.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,38 @@ import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
2525
// Define a union type representing both iterable and non-iterable iterators:
2626
type Iterator = Iter | IterableIterator;
2727

28+
/**
29+
* Checks whether an iterated value passes a test.
30+
*
31+
* @returns boolean indicating whether an iterated value passes a test
32+
*/
33+
type Nullary = () => boolean;
34+
35+
/**
36+
* Checks whether an iterated value passes a test.
37+
*
38+
* @param value - iterated value
39+
* @returns boolean indicating whether an iterated value passes a test
40+
*/
41+
type Unary = ( value: any ) => boolean;
42+
43+
/**
44+
* Checks whether an iterated value passes a test.
45+
*
46+
* @param value - iterated value
47+
* @param i - iteration index
48+
* @returns boolean indicating whether an iterated value passes a test
49+
*/
50+
type Binary = ( value: any, i: number ) => boolean;
51+
2852
/**
2953
* Checks whether an iterated value passes a test.
3054
*
3155
* @param value - iterated value
3256
* @param i - iteration index
3357
* @returns boolean indicating whether an iterated value passes a test
3458
*/
35-
type Predicate = ( value?: any, i?: number ) => boolean;
59+
type Predicate = Nullary | Unary | Binary;
3660

3761
/**
3862
* Returns an iterator which rejects a provided iterator's values according to a predicate function.

lib/node_modules/@stdlib/iter/reject/docs/types/test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ function iterator() {
4444
/**
4545
* Predicate function.
4646
*
47+
* @param _v - iterated value
48+
* @param i - iteration index
4749
* @returns a boolean
4850
*/
49-
function predicate1() {
50-
return false;
51+
function predicate1( _v: any, i: number ): boolean { // tslint:disable-line:variable-name
52+
return ( i > 5 );
5153
}
5254

5355
/**
5456
* Predicate function.
5557
*
58+
* @param v - iterated value
5659
* @returns a boolean
5760
*/
58-
function predicate2() {
59-
return true;
61+
function predicate2( v: any ): boolean {
62+
return ( v !== v );
6063
}
6164

6265

0 commit comments

Comments
 (0)