Last active
August 29, 2015 14:25
-
-
Save briancavalier/3d7a7ebb6318c5d57c11 to your computer and use it in GitHub Desktop.
Creed +ES6 solution to https://github.com/plaid/async-problem
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
| 'use strict'; | |
| import { runNode, all, coroutine } from 'creed'; | |
| import { readFile } from 'fs'; | |
| import { join } from 'path'; | |
| const joinPath = init => tail => join(init, tail); | |
| const readFileP = encoding => file => runNode(readFile, file, {encoding}); | |
| const compose = (f, g) => x => g(f(x)); | |
| const concatFiles = coroutine(function* (dir) { | |
| const readUtf8P = compose(joinPath(dir), readFileP('utf8')); | |
| const index = yield readUtf8P('index.txt'); | |
| const results = yield all(index.match(/^.*(?=\n)/gm).map(readUtf8P)); | |
| return results.join(''); | |
| }); | |
| const main = () => { | |
| concatFiles(process.argv[2]) | |
| .then(s => process.stdout.write(s)) | |
| .catch(e => process.stderr.write(e)); | |
| }; | |
| if (process.argv[1] === __filename) main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment