-
Notifications
You must be signed in to change notification settings - Fork 2
/
HighlandHelpers.js
82 lines (80 loc) · 2.07 KB
/
HighlandHelpers.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const _ = require('highland');
module.exports = {
mapAsync: _.curry(function (mapper, source) {
return source.consume((err, v, push, next) => {
if (err) {
push(err);
next();
}
else if (v === _.nil) {
push(null, v);
}
else {
mapper(v)
.then((v) => {
push(null, v);
next();
});
}
})
}),
splitArray: function (source) {
return source.consume((err, v, push, next) => {
if (err) {
push(err);
next();
}
else if (v === _.nil) {
push(null, v);
}
else {
if (Array.isArray(v)) {
v.forEach((item) => {
push(null, item);
});
} else {
push(null, v);
}
next();
}
})
},
dotoAsync: _.curry(function (f, source) {
return source.consume((err, v, push, next) => {
if (err) {
push(err);
next();
}
else if (v === _.nil) {
push(null, v);
}
else {
f(v)
.then(() => {
push(null, v);
next();
});
}
})
}),
filterAsync: _.curry(function (f, source) {
return source.consume((err, v, push, next) => {
if (err) {
push(err);
next();
}
else if (v === _.nil) {
push(null, v);
}
else {
f(v)
.then((result) => {
if (result) {
push(null, v);
}
next();
});
}
})
}),
};