@@ -7,35 +7,36 @@ const LazyEither = require('lazy-either');
7
7
const R = require ( 'ramda' ) ;
8
8
const S = require ( 'sanctuary' ) ;
9
9
10
- // join :: String -> String -> String
10
+
11
+ // join :: String -> String -> String
11
12
const join = R . curryN ( 2 , path . join ) ;
12
13
13
- // readFile :: String -> String -> LazyEither Error String
14
+ // readFile :: String -> String -> LazyEither Error String
14
15
const readFile = R . curry ( ( encoding , filename ) =>
15
16
new LazyEither ( resolve => {
16
- fs . readFile ( filename , { encoding : encoding } , ( err , data ) =>
17
- resolve ( err !== null ? S . Left ( err ) : S . Right ( data ) ) ) ;
17
+ fs . readFile (
18
+ filename ,
19
+ { encoding : encoding } ,
20
+ ( err , data ) => resolve ( err != null ? S . Left ( err ) : S . Right ( data ) )
21
+ ) ;
18
22
} ) ) ;
19
23
20
- // readFiles :: [String] -> LazyEither Error String
21
- const readFiles = R . traverse ( LazyEither . of , readFile ( 'utf8' ) ) ;
22
-
23
- // concatFiles :: String -> LazyEither Error String
24
+ // concatFiles :: String -> LazyEither Error String
24
25
const concatFiles = dir =>
25
26
S . pipe ( [ readFile ( 'utf8' ) ,
26
27
R . map ( S . lines ) ,
27
28
R . map ( R . map ( join ( dir ) ) ) ,
28
- R . chain ( readFiles ) ,
29
+ R . chain ( R . traverse ( LazyEither . of , readFile ( 'utf8' ) ) ) ,
29
30
R . map ( R . join ( '' ) ) ] ,
30
31
join ( dir , 'index.txt' ) )
31
32
33
+
32
34
const main = ( ) => {
33
35
concatFiles ( process . argv [ 2 ] ) . value ( either => {
34
36
if ( either . isRight ) {
35
37
process . stdout . write ( either . value ) ;
36
38
process . exit ( 0 ) ;
37
- }
38
- else {
39
+ } else {
39
40
process . stderr . write ( String ( either . value ) + '\n' ) ;
40
41
process . exit ( 1 ) ;
41
42
}
0 commit comments