(f: (i: number) => A, options?: {
readonly length?: number
})
| 54 | * @since 2.0.0 |
| 55 | */ |
| 56 | export const makeBy = <A>(f: (i: number) => A, options?: { |
| 57 | readonly length?: number |
| 58 | }): Iterable<A> => { |
| 59 | const max = options?.length !== undefined ? Math.max(1, Math.floor(options.length)) : Infinity |
| 60 | return { |
| 61 | [Symbol.iterator]() { |
| 62 | let i = 0 |
| 63 | return { |
| 64 | next(): IteratorResult<A> { |
| 65 | if (i < max) { |
| 66 | return { value: f(i++), done: false } |
| 67 | } |
| 68 | return { done: true, value: undefined } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns an iterable of integers starting at `start` and increasing by `1`. |
no outgoing calls
no test coverage detected