Skip to content

Commit 9943f27

Browse files
feat(iter/cartesian-square): add docs/types/test.ts
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent c658542 commit 9943f27

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
24+
import { ArrayLike } from '@stdlib/types/array';
25+
26+
// Define a union type representing both iterable and non-iterable iterators:
27+
type Iterator = Iter | IterableIterator;
28+
29+
/**
30+
* Returns an iterator which iteratively computes the Cartesian square.
31+
*
32+
* @param x - input array
33+
* @throws {TypeError} first argument must be a collection
34+
* @returns iterator
35+
*
36+
* @example
37+
* var x = [ 1, 2 ];
38+
*
39+
* var iter = iterCartesianSquare( x );
40+
*
41+
* var v = iter.next().value;
42+
* // returns [ 1, 1 ]
43+
*
44+
* v = iter.next().value;
45+
* // returns [ 1, 2 ]
46+
*
47+
* v = iter.next().value;
48+
* // returns [ 2, 1 ]
49+
*
50+
* // ...
51+
*/
52+
declare function iterCartesianSquare<T>( x: ArrayLike<T> & object ): Iterator;
53+
54+
55+
// EXPORTS //
56+
57+
export = iterCartesianSquare;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 iterCartesianSquare = require( './index' );
20+
21+
// TESTS //
22+
23+
// The function returns an iterator...
24+
{
25+
iterCartesianSquare( [ 1, 2 ] ); // $ExpectType Iterator
26+
}
27+
28+
// The compiler throws an error if the function is provided a value other than an iterator protocol-compliant object...
29+
{
30+
iterCartesianSquare( '5' ); // $ExpectError
31+
iterCartesianSquare( 5 ); // $ExpectError
32+
iterCartesianSquare( NaN ); // $ExpectError
33+
iterCartesianSquare( true ); // $ExpectError
34+
iterCartesianSquare( false ); // $ExpectError
35+
iterCartesianSquare( null ); // $ExpectError
36+
iterCartesianSquare( undefined ); // $ExpectError
37+
iterCartesianSquare( {} ); // $ExpectError
38+
}
39+
40+
// The compiler throws an error if the function is provided insufficient arguments...
41+
{
42+
iterCartesianSquare(); // $ExpectError
43+
}

0 commit comments

Comments
 (0)