Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
Created February 18, 2016 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangchiqing/2fc6cb718fc9dac12dcb to your computer and use it in GitHub Desktop.
Save zhangchiqing/2fc6cb718fc9dac12dcb to your computer and use it in GitHub Desktop.
lift Promise
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