Skip to content

Instantly share code, notes, and snippets.

@JuanCaicedo
Created February 16, 2016 22:40
Show Gist options
  • Save JuanCaicedo/88775e0e8ec92c3d2922 to your computer and use it in GitHub Desktop.
Save JuanCaicedo/88775e0e8ec92c3d2922 to your computer and use it in GitHub Desktop.
Comparing partially applied functions to currying
/* partially-applied.js */
function funcLog(item){
return function log(msg){
console.log('Item = ' + item + '. Msg = ' + msg);
}
}
module.exports {
funcLog: funcLog
}
/* for-curry.js */
function log(item, msg){
console.log('Item = ' + item + '. Msg = ' + msg);
}
}
module.exports {
log: log
}
/* main.js */
var _ = require('lodash');
var Bluebird = require('bluebird');
var partiallyApplied = require('./partially-applied');
var forCurry = require('./for-curry');
//partially applied version
var log = partiallyApplied.funcLog('association')
Bluebird.resolve('test message')
.tap(log)
//partially applied version
var log = _.curry(forCurry.log)('association')
Bluebird.resolve('test message')
.tap(log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment