Created
May 10, 2017 16:29
-
-
Save ecancino/737f1a2143790fbd3e1fe4e2db9b55fc to your computer and use it in GitHub Desktop.
Cat files in folder
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 { 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