Created
February 16, 2016 22:40
-
-
Save JuanCaicedo/88775e0e8ec92c3d2922 to your computer and use it in GitHub Desktop.
Comparing partially applied functions to currying
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
/* 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