1 var assert = require("assert")
2 var dezalgoify = require("dezalgo")
7 * short-circuited async Array.prototype.some implementation
9 * Serially evaluates a list of values from a JS array or arraylike
10 * against an asynchronous predicate, terminating on the first truthy
11 * value. If the predicate encounters an error, pass it to the completion
12 * callback. Otherwise, pass the truthy value passed by the predicate, or
13 * `false` if no truthy value was passed.
15 function some (list, test, cb) {
16 assert("length" in list, "array must be arraylike")
17 assert.equal(typeof test, "function", "predicate must be callable")
18 assert.equal(typeof cb, "function", "callback must be callable")
20 var array = slice(list)
22 , length = array.length
23 , hecomes = dezalgoify(cb)
28 if (index >= length) return hecomes(null, false)
30 test(array[index], reduce)
33 function reduce (er, result) {
34 if (er) return hecomes(er, false)
35 if (result) return hecomes(null, result)
42 // Array.prototype.slice on arguments arraylike is expensive
43 function slice(args) {
44 var l = args.length, a = [], i
45 for (i = 0; i < l; i++) a[i] = args[i]