Created
June 8, 2012 13:54
-
-
Save jonpacker/2895725 to your computer and use it in GitHub Desktop.
This file contains 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
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