|
| 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 | +interface Options { |
| 22 | + /** |
| 23 | + * Number of iterations. |
| 24 | + */ |
| 25 | + iter?: number; |
| 26 | +} |
| 27 | + |
| 28 | +interface Iterator { |
| 29 | + /** |
| 30 | + * Returns an iterator protocol-compliant object containing the next iterated value (if one exists) and a boolean flag indicating whether the iterator is finished. |
| 31 | + * |
| 32 | + * @returns iterator protocol-compliant object |
| 33 | + */ |
| 34 | + next(): IteratorResult; |
| 35 | + |
| 36 | + /** |
| 37 | + * Finishes an iterator. |
| 38 | + * |
| 39 | + * @param value - value to return |
| 40 | + * @returns iterator protocol-compliant object |
| 41 | + */ |
| 42 | + return( value?: any ): IteratorResult; |
| 43 | +} |
| 44 | + |
| 45 | +interface IterableIterator extends Iterator { |
| 46 | + /** |
| 47 | + * Returns a new iterable iterator. |
| 48 | + * |
| 49 | + * @returns iterable iterator |
| 50 | + */ |
| 51 | + [Symbol.iterator](): IterableIterator; |
| 52 | +} |
| 53 | + |
| 54 | +interface IteratorResult { |
| 55 | + /** |
| 56 | + * Iterated value (if one exists). |
| 57 | + */ |
| 58 | + value?: any; |
| 59 | + |
| 60 | + /** |
| 61 | + * Boolean flag indicating whether the iterator is finished. |
| 62 | + */ |
| 63 | + done: boolean; |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | +* Returns an iterator which always returns the same value. |
| 68 | +* |
| 69 | +* ## Notes |
| 70 | +* |
| 71 | +* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. |
| 72 | +* |
| 73 | +* @param value - value to return |
| 74 | +* @param options - function options |
| 75 | +* @param options.iter - number of iterations (default: 1e308) |
| 76 | +* @throws `iter` option must be a nonnegative integer |
| 77 | +* @returns iterator |
| 78 | +* |
| 79 | +* @example |
| 80 | +* |
| 81 | +* var iter = iterConstant( 3.14 ); |
| 82 | +* |
| 83 | +* var v = iter.next().value; |
| 84 | +* // returns 3.14 |
| 85 | +* |
| 86 | +* v = iter.next().value; |
| 87 | +* // returns 3.14 |
| 88 | +* |
| 89 | +* v = iter.next().value; |
| 90 | +* // returns 3.14 |
| 91 | +* |
| 92 | +* // ... |
| 93 | +*/ |
| 94 | +declare function iterConstant( value: any, options?: Options ): Iterator | IterableIterator; // tslint:disable-line:max-line-length |
| 95 | + |
| 96 | + |
| 97 | +// EXPORTS // |
| 98 | + |
| 99 | +export = iterConstant; |
0 commit comments