diff options
Diffstat (limited to 'lib/utils/promise.js')
-rw-r--r-- | lib/utils/promise.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/utils/promise.js b/lib/utils/promise.js index c25b349..82f4a60 100644 --- a/lib/utils/promise.js +++ b/lib/utils/promise.js @@ -21,6 +21,18 @@ function serie(arr, iter, base) { }, []); } +// Iter over an array and return first result (not null) +function some(arr, iter) { + return _.reduce(arr, function(prev, elem, i) { + return prev.then(function(val) { + if (val) return val; + + return iter(elem, i); + }); + }, Q()); +} + module.exports = Q; module.exports.reduce = reduce; module.exports.serie = serie; +module.exports.some = some; |