Created
May 5, 2012 22:06
-
-
Save jonpacker/2605881 to your computer and use it in GitHub Desktop.
Making a meal for Helge
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
var naan = require('naan'); | |
var fs = require('fs'); | |
// With naan.cook: | |
var makeHelgesMeal = naan.cook( | |
naan.curry(fs.writeFile, "bobby"), | |
naan.curry(fs.readFile, "bob") | |
); | |
makeHelgesMeal(function(err) {}); | |
// Without naan.cook: | |
var makeHelgesUntastyMeal = function(callback) { | |
fs.readFile("bob", function(err, data) { | |
if (err) { | |
callback(err); | |
} else { | |
fs.writeFile("bobby", data, callback); | |
} | |
}); | |
} | |
makeHelgesUntastyMeal(function(err) {}); | |
// naan.cook broken down, all params supplied | |
var fn = naan.curry(fs.writeFile, "bobby"); // the function to curry | |
var ingredients = [ naan.curry(fs.readFile, "bob") ]; // the params to resolve before calling the curry | |
var recipe = true; // the location of the params in the curry - in this case, `true` means 'at the start' | |
var callbackPosition = false; // where to look for the callback in the resulting curry when it's called. a falsy value means it is assumed to be the last param | |
var notParallel = false; // run the ingredients in parallel. in this case it doesn't matter | |
var meal = naan.cook(fn, ingredients, recipe, callbackPosition, notParallel); | |
meal(function(err) {}); | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment