Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Commit d15c4f8

Browse files
committed
Merge pull request #24 from Risto-Stevcev/master
Added most
2 parents ce67a24 + 963cb64 commit d15c4f8

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The solutions are best read in the following order:
2424
- [__righto.js__](./righto.js)
2525
- [__promises.js__](./promises.js)
2626
- [__promises-ramda.js__](./promises-ramda.js)
27+
- [__most.js__](./most.js)
2728
- [__coroutines-co.js__](./coroutines-co.js)
2829
- [__coroutines-bluebird.js__](./coroutines-bluebird.js)
2930
- [__await.js__](./await.js)

most.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const most = require('most');
7+
const R = require('ramda');
8+
const S = require('sanctuary');
9+
10+
11+
// join :: String -> String -> String
12+
const join = R.curryN(2, path.join);
13+
14+
// readFile :: String -> String -> Promise Error String
15+
const readFile = R.curry((encoding, filename) =>
16+
new Promise((resolve, reject) =>
17+
fs.readFile(filename, { encoding: encoding }, (err, data) =>
18+
err != null ? reject(err) : resolve(data)
19+
)));
20+
21+
// concatFiles :: String -> Promise Error String
22+
const concatFiles = dir =>
23+
R.pipe(R.pipe(readFile('utf8'), most.fromPromise),
24+
R.map(S.lines),
25+
R.map(R.map(join(dir))),
26+
R.chain(R.pipe(R.map(readFile('utf8')), most.from)),
27+
stream => stream.await(),
28+
R.reduce(R.concat, '')
29+
)(join(dir, 'index.txt'));
30+
31+
32+
const main = () => {
33+
concatFiles(process.argv[2]).then(value => {
34+
process.stdout.write(value);
35+
process.exit(0);
36+
}, err => {
37+
process.stderr.write(String(err) + '\n');
38+
process.exit(1);
39+
});
40+
};
41+
42+
if (process.mainModule.filename === __filename) main();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"foreign": "1.0.x",
1313
"kgo": "3.1.x",
1414
"lazy-either": "1.0.x",
15+
"most": "0.18.x",
1516
"ramda": "0.19.x",
1617
"righto": "0.3.x",
1718
"sanctuary": "0.9.x"

test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ test kgo.js
5757
test righto.js
5858
test promises.js
5959
test promises-ramda.js
60+
test most.js
6061
test coroutines-co.js
6162
test coroutines-bluebird.js
6263
test await.compiled.js

0 commit comments

Comments
 (0)