README.md (3973B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # iterPositiveIntegersSeq 22 23 > Create an iterator which generates a positive integer sequence. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 The sequence of positive integers `1, 2, 3, 4, ...` (OEIS [A000027][oeis-a000027]) is also commonly referred to the sequence of **natural numbers**, **whole numbers**, and **counting numbers**; however, those terms are ambiguous due to the inclusion or exclusion of `0`. 30 31 </section> 32 33 <!-- /.intro --> 34 35 <!-- Package usage documentation. --> 36 37 <section class="usage"> 38 39 ## Usage 40 41 ```javascript 42 var iterPositiveIntegersSeq = require( '@stdlib/math/iter/sequences/positive-integers' ); 43 ``` 44 45 #### iterPositiveIntegersSeq( \[options] ) 46 47 Returns an iterator which generates a positive integer sequence. 48 49 ```javascript 50 var it = iterPositiveIntegersSeq(); 51 // returns <Object> 52 53 var v = it.next().value; 54 // returns 1 55 56 v = it.next().value; 57 // returns 2 58 59 v = it.next().value; 60 // returns 3 61 62 // ... 63 ``` 64 65 The returned iterator protocol-compliant object has the following properties: 66 67 - **next**: function which returns an iterator 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 is finished. 68 - **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. 69 70 The function supports the following `options`: 71 72 - **iter**: number of iterations. Default: `9007199254740991`. 73 74 By default, the function returns a finite iterator to avoid exceeding the maximum safe double-precision floating-point integer. To adjust the number of iterations, set the `iter` option. 75 76 ```javascript 77 var opts = { 78 'iter': 2 79 }; 80 var it = iterPositiveIntegersSeq( opts ); 81 // returns <Object> 82 83 var v = it.next().value; 84 // returns 1 85 86 v = it.next().value; 87 // returns 2 88 89 var bool = it.next().done; 90 // returns true 91 ``` 92 93 </section> 94 95 <!-- /.usage --> 96 97 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 98 99 <section class="notes"> 100 101 ## Notes 102 103 - If an environment supports `Symbol.iterator`, the returned iterator is iterable. 104 105 </section> 106 107 <!-- /.notes --> 108 109 <!-- Package usage examples. --> 110 111 <section class="examples"> 112 113 ## Examples 114 115 <!-- eslint no-undef: "error" --> 116 117 ```javascript 118 var iterPositiveIntegersSeq = require( '@stdlib/math/iter/sequences/positive-integers' ); 119 120 // Create an iterator: 121 var opts = { 122 'iter': 100 123 }; 124 var it = iterPositiveIntegersSeq( opts ); 125 126 // Perform manual iteration... 127 var v; 128 while ( true ) { 129 v = it.next(); 130 if ( v.done ) { 131 break; 132 } 133 console.log( v.value ); 134 } 135 ``` 136 137 </section> 138 139 <!-- /.examples --> 140 141 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 142 143 <section class="references"> 144 145 </section> 146 147 <!-- /.references --> 148 149 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 150 151 <section class="links"> 152 153 [oeis-a000027]: http://oeis.org/A000027 154 155 </section> 156 157 <!-- /.links -->