pragmatic-fp-ts
Version:
Opinionated functional programming library with easy use in mind
15 lines (14 loc) • 441 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InfiniteArray = void 0;
function InfiniteArray(calcElem) {
return new Proxy([], {
get(_, key) {
if (key === "length")
return Number.POSITIVE_INFINITY;
const idx = typeof key === "string" ? parseInt(key) : key;
return calcElem(idx);
},
});
}
exports.InfiniteArray = InfiniteArray;