Last active
August 29, 2015 14:16
-
-
Save gr0uch/f9f86790c4ae93d1de11 to your computer and use it in GitHub Desktop.
Serial execution of functions for flow based programming.
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
/** | |
* Take an array of functions that accept one argument and return a value or Promise, | |
* and invoke each function serially, passing the resolved value to the next function. | |
* | |
* @param {Array} fnArray | |
* @param {Mixed} initialValue | |
* @return {Promise} | |
*/ | |
export default (fnArray, initialValue) => | |
fnArray.reduce((chain, fn, index) => | |
index === 0 ? Promise.resolve(fn(initialValue)) : | |
chain.then(value => fn(value))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment