Skip to content

Instantly share code, notes, and snippets.

@MiracleBlue
Last active November 26, 2016 10:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiracleBlue/c6a9800700a47f7a14e4805f13461246 to your computer and use it in GitHub Desktop.
Save MiracleBlue/c6a9800700a47f7a14e4805f13461246 to your computer and use it in GitHub Desktop.
// So this is fking incredible. Its actually possible to
// do totally immutable state inside a generator.
// No mutations. No 'let's. No shame!
function* range(start, end, step = 1, current = start) {
yield current;
if (current < end) yield* range(start, end, step, current + step);
}
// In the name of the Turing, and of the Crockford, and of the holy Atwood, Amen.
console.log(...range(5, 15));
// => 5 6 7 8 9 10 11 12 13 14 15
console.log(...range(5, 15, 2));
// => 5 7 9 11 13 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment