-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
45 lines (41 loc) · 1.05 KB
/
utils.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
/*
* collection of 'generic' useful functions
*/
/**
* curry
* with courtesy of M@DNIFICENT
* e.g. \
*
* sayHello = function (user, target) {
* return window.alert(user + " -> " + target + " :: Hello!");
* };
* sayHelloAad = curry(sayHello, "Aad");
* sayHelloAad("Felix");
*
*/
function curry() {
var slice = [].slice;
var args, fn;
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
return function() {
var appendedArgs;
appendedArgs = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return fn.apply(null, slice.call(args).concat(slice.call(appendedArgs)));
};
};
function promisesReduce(promises, func, init){
return Promise.all(promises)
.then(function(results){
return results.reduce(func, init);
})
.catch(passRejectedPromise);
}
//see: https://github.com/nodejs/node/issues/2181 why this function exists
function passRejectedPromise(err){
return Promise.reject(err)
}
module.exports = {
curry: curry,
promisesReduce: promisesReduce,
passRejectedPromise: passRejectedPromise
}