UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

10 lines (9 loc) 307 B
export function InfiniteArray<A>(calcElem: (idx: number) => A): A[] { return new Proxy([], { get(_, key) { if (key === "length") return Number.POSITIVE_INFINITY; const idx = typeof key === "string" ? parseInt(key) : ((key as unknown) as number); return calcElem(idx); }, }); }