-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.js
43 lines (38 loc) · 882 Bytes
/
example.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
var compose = require('compose-function')
var c = require('./')
var excitedly = compose(
c.join,
c.map(function (data) {
return c.either(
function onErr (err) {
return c.of('booo')
},
function (val) {
return c.of(val)
},
someIO(data + ' wooo')
)
}),
c.map(function (data) {
return data + '!!!'
})
)
excitedly(someIO('this is a value'))(function (err, val) {
console.log(err, val)
})
function someIO (data, cb) {
if (!cb) return function (_cb) {
return someIO(data, _cb)
}
process.nextTick(function () {
cb(null, data)
})
}
function ioError (data, cb) {
if (!cb) return function (_cb) {
return ioError(data, _cb)
}
process.nextTick(function () {
cb(new Error('rarrr'))
})
}