— What you mean by "lazy list"?
— Infinite lists for instance
— Fibonacci, natural numbers, etc
— Oke, infinite loop in code.. you mean "lazy list", oke
—
function* numbers() {
let i = 0;
while (true)
yield ++i;
}
— A generator makes caching like this effortless
— Since it stores the state of the function on every yield
— It's like a horse in a vacuum imo
—
for(const n of numbers()) {
if (n >= 10)
break;
console.log(n);
}
// logs numbers 1-9