Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save briancavalier/3d7a7ebb6318c5d57c11 to your computer and use it in GitHub Desktop.

Select an option

Save briancavalier/3d7a7ebb6318c5d57c11 to your computer and use it in GitHub Desktop.
'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