README.md (3913B)
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 # iterPositiveEvenIntegersSeq 22 23 > Create an iterator which generates a sequence of [positive even integers][oeis-a299174]. 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 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 <!-- eslint-disable id-length --> 40 41 ```javascript 42 var iterPositiveEvenIntegersSeq = require( '@stdlib/math/iter/sequences/positive-even-integers' ); 43 ``` 44 45 #### iterPositiveEvenIntegersSeq( \[options] ) 46 47 Returns an iterator which generates a sequence of positive even integers. 48 49 <!-- eslint-disable id-length --> 50 51 ```javascript 52 var it = iterPositiveEvenIntegersSeq(); 53 // returns <Object> 54 55 var v = it.next().value; 56 // returns 2 57 58 v = it.next().value; 59 // returns 4 60 61 v = it.next().value; 62 // returns 6 63 64 // ... 65 ``` 66 67 The returned iterator protocol-compliant object has the following properties: 68 69 - **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. 70 - **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. 71 72 The function supports the following `options`: 73 74 - **iter**: number of iterations. Default: `4503599627370496`. 75 76 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. 77 78 <!-- eslint-disable id-length --> 79 80 ```javascript 81 var opts = { 82 'iter': 2 83 }; 84 var it = iterPositiveEvenIntegersSeq( opts ); 85 // returns <Object> 86 87 var v = it.next().value; 88 // returns 2 89 90 v = it.next().value; 91 // returns 4 92 93 var bool = it.next().done; 94 // returns true 95 ``` 96 97 </section> 98 99 <!-- /.usage --> 100 101 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 102 103 <section class="notes"> 104 105 ## Notes 106 107 - If an environment supports `Symbol.iterator`, the returned iterator is iterable. 108 109 </section> 110 111 <!-- /.notes --> 112 113 <!-- Package usage examples. --> 114 115 <section class="examples"> 116 117 ## Examples 118 119 <!-- eslint no-undef: "error" --> 120 121 <!-- eslint-disable id-length --> 122 123 ```javascript 124 var iterPositiveEvenIntegersSeq = require( '@stdlib/math/iter/sequences/positive-even-integers' ); 125 126 // Create an iterator: 127 var opts = { 128 'iter': 100 129 }; 130 var it = iterPositiveEvenIntegersSeq( opts ); 131 132 // Perform manual iteration... 133 var v; 134 while ( true ) { 135 v = it.next(); 136 if ( v.done ) { 137 break; 138 } 139 console.log( v.value ); 140 } 141 ``` 142 143 </section> 144 145 <!-- /.examples --> 146 147 <!-- 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. --> 148 149 <section class="references"> 150 151 </section> 152 153 <!-- /.references --> 154 155 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 156 157 <section class="links"> 158 159 [oeis-a299174]: http://oeis.org/A299174 160 161 </section> 162 163 <!-- /.links -->