Skip to content

Instantly share code, notes, and snippets.

@jonpacker
Created June 8, 2012 13:54
Show Gist options
  • Save jonpacker/2895725 to your computer and use it in GitHub Desktop.
Save jonpacker/2895725 to your computer and use it in GitHub Desktop.
function join() {
return [].join.call(arguments);
}
var readFooFile = naan.curry(fs.readFile, "foo.txt", "utf8");
var readBarFile = naan.curry(fs.readFile, "bar.txt", "utf8");
// readFooFile and readBarFile now take one argument, the callback, and
always
// read either foo.txt or bar.txt.
var joinWithFiles = naan.cook(join, [readFooFile, readBarFile], true, false);
// Now, when joinWithFiles is called, the first two arguments will be the
// contents of foo.txt and bar.txt respectively.
//
// So, if foo.txt contains "Hello", and bar.txt contains "World":
joinWithFiles("!", function(err, value) {
console.log(value); // -> "Hello,World,!"
});
// Also note that `join` didn't have a callback, but since two of the
arguments
// are resolved asynchronously, naan inferred that we needed one now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment