UNPKG

920 BJavaScriptView Raw
1module.exports = {
2 reduce: function (funs) {
3 return function (value, context) {
4 if (!funs.length) throw new Error('depject.reduce: no functions available to reduce')
5 return funs.reduce(function (value, fn) {
6 return fn(value, context)
7 }, value)
8 }
9 },
10 first: function (funs) {
11 return function (value) {
12 if (!funs.length) throw new Error('depject.first: no functions available to take first')
13 var args = [].slice.call(arguments)
14 for (var i = 0; i < funs.length; i++) {
15 var _value = funs[i].apply(this, args)
16 if (_value !== undefined) return _value
17 }
18 }
19 },
20 map: function (funs) {
21 return function (value) {
22 if (!funs.length) throw new Error('depject.map: no functions available to map')
23 var args = [].slice.call(arguments)
24 return funs.map(function (fn) {
25 return fn.apply(this, args)
26 })
27 }
28 }
29}
30