Skip to content

Instantly share code, notes, and snippets.

@keller
Created March 6, 2021 06:11
Show Gist options
  • Save keller/bf757cc06119f8d64603c18f88ee4046 to your computer and use it in GitHub Desktop.
Save keller/bf757cc06119f8d64603c18f88ee4046 to your computer and use it in GitHub Desktop.
function* nums(n) {
yield n;
yield* nums(n + 1);
}
function* primes(seq) {
const prime = seq.next().value;
yield prime;
const nextSeq = function* () {
for (let num of seq) {
if (num % prime !== 0) yield num;
}
};
yield* primes(nextSeq());
}
let i = 0;
for (let n of primes(nums(2))) {
console.log(n);
if (++i >= 100) break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment