-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
46 lines (40 loc) · 1.06 KB
/
index.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
var continuable = {
// take a nested continuable and return the inner one
join: function join (con) {
return function (cb) {
con(function (err, _con) {
if (err) return cb(err)
_con(cb)
})
}
},
// return a new continuable of the predicate(value)
map: function map (fn, con) {
if (!con) return function (c) {
return map(fn, c)
}
return function (cb) {
con(function (err, val) {
if (err) return cb(err)
cb(null, fn(val))
})
}
},
either: function either (left, right, con) {
if (!con) return function (_con) {
return either(left, right, _con)
}
return function (cb) {
con(function (err, val) {
if (err) return left(err)(cb)
return right(val)(cb)
})
}
},
of: function (val) {
return function (cb) {
cb(null, val)
}
}
}
module.exports = continuable