Created
August 15, 2019 21:01
-
-
Save davidroman0O/a806900657f36118ff02cf07b9fe88e6 to your computer and use it in GitHub Desktop.
Pipelines with bluebird
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
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