Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Future = require ('data.future'),
- R = require ('ramda'),
- log = console.log,
- id = function (x) { return x; },
- trampoline = function (fn) {
- return function () {
- var args = arguments;
- var f = function () { return fn.apply (this, args); }
- while (f && typeof f === 'function') { f = f (); };
- return f;
- };
- },
- sequenceF = function (M, fxs) {
- return R.reduce (_perform, M.of ([]), fxs);
- function _perform (acc, f) {
- var ys,
- setYS = function (v) { ys = v; },
- appYS = function (x) { ys = R.append (x, ys); }
- acc.fork (appYS, setYS)
- f.fork (appYS, appYS);
- return M.of (ys);
- };
- },
- sequence = R.curry (function (M, fxs) {
- return R.reduce (_perform, M.of([]), fxs);
- function _perform (acc, f) {
- return acc.chain (function (xs) {
- return f.chain (function (x) {
- return M.of (R.append (x, xs));
- });
- });
- };
- }),
- nil = null;
- (function main () {
- var i = 0, fxs = [];
- for (i = 0; i < 20000 ; i++) {
- fxs = R.append (Future.of (i), fxs);
- }
- sequenceF (Future, fxs).fork (log, log);
- // sequence (Future, fxs).fork (log, log);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement