Skip to content

Instantly share code, notes, and snippets.

@milichev
Created September 27, 2019 13:41
Show Gist options
  • Save milichev/1fa2bcf547cf8f18129a9565d785f807 to your computer and use it in GitHub Desktop.
Save milichev/1fa2bcf547cf8f18129a9565d785f807 to your computer and use it in GitHub Desktop.
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