Created
July 31, 2018 00:20
-
-
Save zerobias/72ed3d3b7caa1ce5562ff8b11ef8c8c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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