repl.txt (5922B)
1 2 {{alias}}( collection, [options,] predicate, done ) 3 Tests whether all elements in a collection fail a test implemented by a 4 predicate function, iterating from right to left. 5 6 When invoked, the predicate function is provided a maximum of four 7 arguments: 8 9 - `value`: collection value 10 - `index`: collection index 11 - `collection`: the input collection 12 - `next`: a callback to be invoked after processing a collection `value` 13 14 The actual number of provided arguments depends on function length. If the 15 predicate function accepts two arguments, the predicate function is 16 provided: 17 18 - `value` 19 - `next` 20 21 If the predicate function accepts three arguments, the predicate function is 22 provided: 23 24 - `value` 25 - `index` 26 - `next` 27 28 For every other predicate function signature, the predicate function is 29 provided all four arguments. 30 31 The `next` callback takes two arguments: 32 33 - `error`: error argument 34 - `result`: test result 35 36 If a provided function calls the `next` callback with a truthy `error` 37 argument, the function suspends execution and immediately calls the `done` 38 callback for subsequent `error` handling. 39 40 The function immediately returns upon encountering a truthy `result` value 41 and calls the `done` callback with `null` as the first argument and `false` 42 as the second argument. 43 44 If all elements fail, the function calls the `done` callback with `null` as 45 the first argument and `true` as the second argument. 46 47 Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, 48 wrap the `done` callback in a function which either executes at the end of 49 the current stack (e.g., `nextTick`) or during a subsequent turn of the 50 event loop (e.g., `setImmediate`, `setTimeout`). 51 52 The function does not support dynamic collection resizing. 53 54 The function does not skip `undefined` elements. 55 56 Parameters 57 ---------- 58 collection: Array|TypedArray|Object 59 Input collection over which to iterate. If provided an object, the 60 object must be array-like (excluding strings and functions). 61 62 options: Object (optional) 63 Function options. 64 65 options.limit: integer (optional) 66 Maximum number of pending invocations. Default: Infinity. 67 68 options.series: boolean (optional) 69 Boolean indicating whether to process each collection element 70 sequentially. Default: false. 71 72 options.thisArg: any (optional) 73 Execution context. 74 75 predicate: Function 76 The test function to invoke for each element in a collection. 77 78 done: Function 79 A callback invoked either upon processing all collection elements or 80 upon encountering an error. 81 82 Examples 83 -------- 84 // Basic usage: 85 > function predicate( value, next ) { 86 ... setTimeout( onTimeout, value ); 87 ... function onTimeout() { 88 ... console.log( value ); 89 ... next( null, false ); 90 ... } 91 ... }; 92 > function done( error, bool ) { 93 ... if ( error ) { 94 ... throw error; 95 ... } 96 ... console.log( bool ); 97 ... }; 98 > var arr = [ 1000, 2500, 3000 ]; 99 > {{alias}}( arr, predicate, done ) 100 1000 101 2500 102 3000 103 true 104 105 // Limit number of concurrent invocations: 106 > function predicate( value, next ) { 107 ... setTimeout( onTimeout, value ); 108 ... function onTimeout() { 109 ... console.log( value ); 110 ... next( null, false ); 111 ... } 112 ... }; 113 > function done( error, bool ) { 114 ... if ( error ) { 115 ... throw error; 116 ... } 117 ... console.log( bool ); 118 ... }; 119 > var opts = { 'limit': 2 }; 120 > var arr = [ 1000, 2500, 3000 ]; 121 > {{alias}}( arr, opts, predicate, done ) 122 2500 123 3000 124 1000 125 true 126 127 // Process sequentially: 128 > function predicate( value, next ) { 129 ... setTimeout( onTimeout, value ); 130 ... function onTimeout() { 131 ... console.log( value ); 132 ... next( null, false ); 133 ... } 134 ... }; 135 > function done( error, bool ) { 136 ... if ( error ) { 137 ... throw error; 138 ... } 139 ... console.log( bool ); 140 ... }; 141 > var opts = { 'series': true }; 142 > var arr = [ 1000, 2500, 3000 ]; 143 > {{alias}}( arr, opts, predicate, done ) 144 3000 145 2500 146 1000 147 true 148 149 150 {{alias}}.factory( [options,] predicate ) 151 Returns a function which tests whether all elements in a collection fail a 152 test implemented by a predicate function, iterating from right to left. 153 154 Parameters 155 ---------- 156 options: Object (optional) 157 Function options. 158 159 options.limit: integer (optional) 160 Maximum number of pending invocations. Default: Infinity. 161 162 options.series: boolean (optional) 163 Boolean indicating whether to process each collection element 164 sequentially. Default: false. 165 166 options.thisArg: any (optional) 167 Execution context. 168 169 predicate: Function 170 The test function to invoke for each element in a collection. 171 172 Returns 173 ------- 174 out: Function 175 A function which tests each element in a collection. 176 177 Examples 178 -------- 179 > function predicate( value, next ) { 180 ... setTimeout( onTimeout, value ); 181 ... function onTimeout() { 182 ... console.log( value ); 183 ... next( null, false ); 184 ... } 185 ... }; 186 > var opts = { 'series': true }; 187 > var f = {{alias}}.factory( opts, predicate ); 188 > function done( error, bool ) { 189 ... if ( error ) { 190 ... throw error; 191 ... } 192 ... console.log( bool ); 193 ... }; 194 > var arr = [ 1000, 2500, 3000 ]; 195 > f( arr, done ) 196 3000 197 2500 198 1000 199 true 200 > arr = [ 1000, 1500, 2000 ]; 201 > f( arr, done ) 202 2000 203 1500 204 1000 205 true 206 207 See Also 208 -------- 209