Skip to content

Instantly share code, notes, and snippets.

@undoZen
Created March 18, 2014 08:34
Show Gist options
  • Save undoZen/9615885 to your computer and use it in GitHub Desktop.
Save undoZen/9615885 to your computer and use it in GitHub Desktop.
var co = require('co');
var thunkify = require('thunkify');
var asyncMath = function (list, cb) {
setTimeout(function () {
cb(null, Math.max.apply(Math, list), Math.min.apply(Math, list));
}, 500);
};
function binary(fn) {
return function (a, b) {
return fn.call(this, a, b);
}
}
function trimBinary(fn) {
return function (f) {
return fn(binary(f));
}
}
function decoBinary(fn) {
return function () {
var f = fn.apply(this, arguments);
return trimBinary(f);
}
}
var show = function () { console.log('show'); console.log(arguments); };
var tam = thunkify(asyncMath);
var ttam = decoBinary(tam);
tam([1,4,7])(show);
tam([2,5,8])(binary(show));
ttam([3,6,9])(show);
co(function *() {
console.log(yield tam([1,2,3,4,5]));
console.log(yield trimBinary(tam([1,2,3,4,5])));
console.log(yield ttam([1,2,3,4,5]));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment