(f: (i: number) => A, options?: {
readonly length?: number
})
| 35 | * @since 2.0.0 |
| 36 | */ |
| 37 | export const makeBy = <A>(f: (i: number) => A, options?: { |
| 38 | readonly length?: number |
| 39 | }): Iterable<A> => { |
| 40 | const max = options?.length !== undefined ? Math.max(1, Math.floor(options.length)) : Infinity |
| 41 | return { |
| 42 | [Symbol.iterator]() { |
| 43 | let i = 0 |
| 44 | return { |
| 45 | next(): IteratorResult<A> { |
| 46 | if (i < max) { |
| 47 | return { value: f(i++), done: false } |
| 48 | } |
| 49 | return { done: true, value: undefined } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Return a `Iterable` containing a range of integers, including both endpoints. |
no outgoing calls
no test coverage detected