Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created July 31, 2018 00:20
Show Gist options
  • Save zerobias/72ed3d3b7caa1ce5562ff8b11ef8c8c8 to your computer and use it in GitHub Desktop.
Save zerobias/72ed3d3b7caa1ce5562ff8b11ef8c8c8 to your computer and use it in GitHub Desktop.
//@flow
function TCROA(iterate) {
return function(initialValue, resolve) {
function next(value) {
setImmediate(() => iterate(value, resolve, next), 0);
}
next(initialValue);
}
}
const factorial = do {
const factorial_ = TCROA(({ n, acc }, resolve, next) => {
if (n === 0) {
return resolve(acc);
} else {
return next({ n: n - 1, acc: n + acc });
}
});
n => factorial_({ n, acc: 1 }, result => console.log(result));
};
factorial(100000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment