-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathfiles.js
56 lines (40 loc) · 900 Bytes
/
files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const isADir = path => path.charAt(path.length - 1) === '/'
const fromPath = path =>
isADir(path) ? Dir(path, path) : File(path, path)
const File = (path, x) => {
const apply = f => f([ path, x ])
const map = (f, _) => File(path, chain(f))
const mapFile = f => map(f, null)
const mapDir = _ => File(path, x)
const inspect = _ => `File(${path}, ${x})`
const chain = (f, _) => apply(f)
return {
map,
mapFile,
mapDir,
inspect,
chain,
fold: chain
}
}
const Dir = (path, x) => {
const apply = g => g([ path, x ])
const map = (_, g) => Dir(path, apply(g))
const mapFile = _ => Dir(path, x)
const mapDir = g => map(null, g)
const inspect = _ => `Dir(${path}, ${x})`
const chain = (_, g) => apply(g)
return {
map,
mapFile,
mapDir,
inspect,
chain,
fold: chain
}
}
module.exports = {
fromPath,
File,
Dir
}