Created
September 27, 2019 13:41
-
-
Save milichev/1fa2bcf547cf8f18129a9565d785f807 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const pipeData = function(fn) { | |
return function(data) { | |
return Promise.resolve(fn(data)).then(function(res) { | |
if (res === void 0) { | |
return data; | |
} | |
const keys = Object.keys(res).filter(function(prop) { | |
return res.hasOwnProperty(prop); | |
}); | |
return Promise.all(keys.map(function(prop) { | |
return res[prop]; | |
})).then(function(vals) { | |
keys.forEach(function(prop, i) { | |
data[prop] = vals[i]; | |
}); | |
return data; | |
}); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment