Skip to content

Instantly share code, notes, and snippets.

@TrevorBasinger
Last active August 29, 2015 14:19
Show Gist options
  • Save TrevorBasinger/d9a38c0f0d75349b4138 to your computer and use it in GitHub Desktop.
Save TrevorBasinger/d9a38c0f0d75349b4138 to your computer and use it in GitHub Desktop.
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);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment