MCPcopy
hub / github.com/Effect-TS/effect / makeBy

Function makeBy

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

Source from the content-addressed store, hash-verified

35 * @since 2.0.0
36 */
37export 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.

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