MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeBy

Function makeBy

packages/effect/src/Iterable.ts:56–73  ·  view source on GitHub ↗
(f: (i: number) => A, options?: {
  readonly length?: number
})

Source from the content-addressed store, hash-verified

54 * @since 2.0.0
55 */
56export 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`.

Callers 5

rangeFunction · 0.85
Array.tsFile · 0.85
rangeFunction · 0.85
Iterable.tsFile · 0.85
rangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected