Skip to content

Instantly share code, notes, and snippets.

@ecancino
Created May 10, 2017 16:29
Show Gist options
  • Select an option

  • Save ecancino/737f1a2143790fbd3e1fe4e2db9b55fc to your computer and use it in GitHub Desktop.

Select an option

Save ecancino/737f1a2143790fbd3e1fe4e2db9b55fc to your computer and use it in GitHub Desktop.
Cat files in folder
const { readdir, readFile, stat } = require('fs-extra');
const { Future } = require('ramda-fantasy');
const { traverse, join, curry } = require('ramda');
//:: String -> Future Error [String]
const ls = path => Future((reject, resolve) =>
readdir(path, (err, files) => err ? reject(err) : resolve(files)));
//:: String -> Future Error String
const cat = curry((path, file) => Future((reject, resolve) =>
readFile(`${path}/${file}`, 'utf8', (err, data) => err ? reject(err) : resolve(data))));
//:: String -> Future Error String
const catDir = dir => ls(dir).chain(traverse(Future.of, cat(dir))).map(join('\n'));
catDir('./texts').fork(console.error, console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment