-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
47 lines (40 loc) · 856 Bytes
/
util.js
File metadata and controls
47 lines (40 loc) · 856 Bytes
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
const util = require('util')
function compose(...args) {
return args.reduce((left, func) => {
return (arg) => { return left(func(arg)) }
})
}
function each(iterator) {
return (iterable) => {
iterable.forEach(iterator)
}
}
function map(iterator) {
return (iterable) => {
return iterable.map(iterator)
}
}
function reduce(iterator, accumulation) {
return (iteratable) => {
return iteratable.reduce(iterator, accumulation)
}
}
function join(joint) {
return (iterable) => iterable.join(joint)
}
function trace(tag) {
return (res) => {
console.log(`${tag}: ${util.inspect(res, {
depth: 9
})}`)
return res
}
}
module.exports = {
compose,
trace,
each,
map,
reduce,
join,
}