Last active
February 27, 2020 17:42
-
-
Save jwulf/60e1d53d0b38056f9acfd82e05946125 to your computer and use it in GitHub Desktop.
A code sample from the article http://joshwulf.com/blog/2020/02/functional-refactor/
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 filereader = wf => typeof wf === 'object' ? wf : read(wf) | |
const read = filename => fs.existsSync(filename) ? | |
{ buffer: fs.readFileSync(filename) } : | |
{ error: filename } | |
const outcomes = workflows.map(filereader) | |
const { error, buffer } = outcomes.reduce((acc, o) => o.error ? | |
{ error: [...acc.error, o.error], buffer: acc.buffer } : | |
{ error: acc.error, buffer: [...acc.buffer, o.buffer] }, | |
{ error: [], buffer: [] }) | |
if (error.length > 0) { | |
throw new Error(`Could not find files: ${error.join(', ')`}) | |
} | |
deploy(buffer.map(makeRequestFromBuffer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment