Skip to content

Commit c9fea25

Browse files
committed
Add Typescript definition
1 parent e938656 commit c9fea25

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
import { Iterator } from '@stdlib/types/iter';
24+
25+
/**
26+
* Returns an iterator which iteratively computes a cumulative maximum value.
27+
*
28+
* ## Notes
29+
*
30+
* - If an environment supports Symbol.iterator, the returned iterator is iterable.
31+
*
32+
* @param iterator - input iterator
33+
* @returns iterator
34+
*
35+
* @example
36+
* var runif = require( '@stdlib/random/iter/uniform' );
37+
*
38+
* var rand = runif( -10.0, 10.0, {
39+
* 'iter': 100
40+
* });
41+
*
42+
* var it = itercumax( rand );
43+
*
44+
* var v = it.next().value;
45+
* // returns <number>
46+
*
47+
* v = it.next().value;
48+
* // returns <number>
49+
*
50+
* v = it.next().value;
51+
* // returns <number>
52+
*
53+
* // ...
54+
*/
55+
declare function itercumax( iterator: Iterator ): Iterator;
56+
57+
58+
// EXPORTS //
59+
60+
export = itercumax;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 itercumax = 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 an iterator...
48+
{
49+
itercumax( iterator() ); // $ExpectType Iterator
50+
}
51+
52+
// The compiler throws an error if the function is provided a value other than an iterator protocol-compliant object...
53+
{
54+
itercumax( '5' ); // $ExpectError
55+
itercumax( 5 ); // $ExpectError
56+
itercumax( true ); // $ExpectError
57+
itercumax( false ); // $ExpectError
58+
itercumax( null ); // $ExpectError
59+
itercumax( undefined ); // $ExpectError
60+
itercumax( [] ); // $ExpectError
61+
itercumax( {} ); // $ExpectError
62+
itercumax( ( x: number ): number => x ); // $ExpectError
63+
}
64+
65+
// The compiler throws an error if the function is provided insufficient arguments...
66+
{
67+
itercumax(); // $ExpectError
68+
}

lib/node_modules/@stdlib/stats/iter/cumax/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)