diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-01-28 18:39:44 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-01-28 18:39:44 +0100 |
commit | 4b465bedea94688a9adfb9136c9d2970d5496274 (patch) | |
tree | 7e29cc10d07b86d86239bd1cd59fab7996b412ce /lib/utils/promise.js | |
parent | 461ef2c68e9086bd77f0a25d57956ebf60308f7c (diff) | |
download | gitbook-4b465bedea94688a9adfb9136c9d2970d5496274.zip gitbook-4b465bedea94688a9adfb9136c9d2970d5496274.tar.gz gitbook-4b465bedea94688a9adfb9136c9d2970d5496274.tar.bz2 |
Fix tests for languages parsing
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; |