Skip to content

Instantly share code, notes, and snippets.

@davidroman0O
Created August 15, 2019 21:01
Show Gist options
  • Save davidroman0O/a806900657f36118ff02cf07b9fe88e6 to your computer and use it in GitHub Desktop.
Save davidroman0O/a806900657f36118ff02cf07b9fe88e6 to your computer and use it in GitHub Desktop.
Pipelines with bluebird
const Promise = require("bluebird");
// It's that simple
const Pipeline = async a => {
return await Promise.reduce(
a.slice(1, a.length),
(ac, cv) => {
return cv(ac);
},
a[0]
);
};
const capitalize = str => str[0].toUpperCase() + str.substring(1);
const splitOnSpaces = str => str.trim().split(" ");
const getLastOfArr = arr => arr.pop();
const toUpper = values => values.toUpperCase();
const wait = async values => {
await Promise.delay(500);
return values;
};
Pipeline([
"david roman",
capitalize,
wait,
splitOnSpaces,
getLastOfArr,
toUpper
]).then(data => console.log(data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment