Created
February 18, 2016 19:00
-
-
Save zhangchiqing/2fc6cb718fc9dac12dcb to your computer and use it in GitHub Desktop.
lift Promise
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 R = require('ramda'); | |
var Promise = require('bluebird'); | |
var liftP2 = R.curry(function(fn, p1, p2) { | |
return Promise.all([p1, p2]).then(R.apply(fn)); | |
}); | |
R.lift(R.add)([1], [2]) | |
// => [3] | |
liftP2(R.add)(Promise.resolve(1), Promise.resolve(2)) | |
.then(console.log); | |
// => 3 | |
var liftP = function(fn) { | |
return function() { | |
return Promise.all(R.slice(0, Infinity, arguments)).then(R.apply(fn)); | |
}; | |
}; | |
liftP(R.add)(Promise.resolve(1), Promise.resolve(2)).then(console.log) | |
// => 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment