README.md (3663B)
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 # iterCubesSeq 22 23 > Create an iterator which generates a sequence of [cubes][oeis-a000578]. 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 ```javascript 40 var iterCubesSeq = require( '@stdlib/math/iter/sequences/cubes' ); 41 ``` 42 43 #### iterCubesSeq( \[options] ) 44 45 Returns an iterator which generates a sequence of cubes. 46 47 ```javascript 48 var it = iterCubesSeq(); 49 // returns <Object> 50 51 var v = it.next().value; 52 // returns 0 53 54 v = it.next().value; 55 // returns 1 56 57 v = it.next().value; 58 // returns 8 59 60 v = it.next().value; 61 // returns 27 62 63 v = it.next().value; 64 // returns 64 65 66 // ... 67 ``` 68 69 The returned iterator protocol-compliant object has the following properties: 70 71 - **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. 72 - **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. 73 74 The function supports the following `options`: 75 76 - **iter**: number of iterations. Default: `208063`. 77 78 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. 79 80 ```javascript 81 var opts = { 82 'iter': 2 83 }; 84 var it = iterCubesSeq( opts ); 85 // returns <Object> 86 87 var v = it.next().value; 88 // returns 0 89 90 v = it.next().value; 91 // returns 1 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 ```javascript 122 var iterCubesSeq = require( '@stdlib/math/iter/sequences/cubes' ); 123 124 // Create an iterator: 125 var opts = { 126 'iter': 100 127 }; 128 var it = iterCubesSeq( opts ); 129 130 // Perform manual iteration... 131 var v; 132 while ( true ) { 133 v = it.next(); 134 if ( v.done ) { 135 break; 136 } 137 console.log( v.value ); 138 } 139 ``` 140 141 </section> 142 143 <!-- /.examples --> 144 145 <!-- 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. --> 146 147 <section class="references"> 148 149 </section> 150 151 <!-- /.references --> 152 153 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 154 155 <section class="links"> 156 157 [oeis-a000578]: https://oeis.org/A000578 158 159 </section> 160 161 <!-- /.links -->