time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (5992B)


      1 
      2 {{alias}}( collection, n, [options,] predicate, done )
      3     Tests whether a collection contains at least `n` elements which pass a test
      4     implemented by a predicate function.
      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 receiving `n` non-falsy `result`
     41     values and calls the `done` callback with `null` as the first argument and
     42     `true` as the second argument.
     43 
     44     If all elements fail, the function calls the `done` callback with `null`
     45     as the first argument and `false` 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     n: number
     63         Minimum number of successful elements.
     64 
     65     options: Object (optional)
     66         Function options.
     67 
     68     options.limit: integer (optional)
     69         Maximum number of pending invocations. Default: Infinity.
     70 
     71     options.series: boolean (optional)
     72         Boolean indicating whether to process each collection element
     73         sequentially. Default: false.
     74 
     75     options.thisArg: any (optional)
     76         Execution context.
     77 
     78     predicate: Function
     79         The test function to invoke for each element in a collection.
     80 
     81     done: Function
     82         A callback invoked either upon processing all collection elements or
     83         upon encountering an error.
     84 
     85     Examples
     86     --------
     87     // Basic usage:
     88     > function predicate( value, next ) {
     89     ...     setTimeout( onTimeout, value );
     90     ...     function onTimeout() {
     91     ...         console.log( value );
     92     ...         next( null, false );
     93     ...     }
     94     ... };
     95     > function done( error, bool ) {
     96     ...     if ( error ) {
     97     ...         throw error;
     98     ...     }
     99     ...     console.log( bool );
    100     ... };
    101     > var arr = [ 3000, 2500, 1000 ];
    102     > {{alias}}( arr, 2, predicate, done )
    103     1000
    104     2500
    105     3000
    106     false
    107 
    108     // Limit number of concurrent invocations:
    109     > function predicate( value, next ) {
    110     ...     setTimeout( onTimeout, value );
    111     ...     function onTimeout() {
    112     ...         console.log( value );
    113     ...         next( null, false );
    114     ...     }
    115     ... };
    116     > function done( error, bool ) {
    117     ...     if ( error ) {
    118     ...         throw error;
    119     ...     }
    120     ...     console.log( bool );
    121     ... };
    122     > var opts = { 'limit': 2 };
    123     > var arr = [ 3000, 2500, 1000 ];
    124     > {{alias}}( arr, 2, opts, predicate, done )
    125     2500
    126     3000
    127     1000
    128     false
    129 
    130     // Process sequentially:
    131     > function predicate( value, next ) {
    132     ...     setTimeout( onTimeout, value );
    133     ...     function onTimeout() {
    134     ...         console.log( value );
    135     ...         next( null, false );
    136     ...     }
    137     ... };
    138     > function done( error, bool ) {
    139     ...     if ( error ) {
    140     ...         throw error;
    141     ...     }
    142     ...     console.log( bool );
    143     ... };
    144     > var opts = { 'series': true };
    145     > var arr = [ 3000, 2500, 1000 ];
    146     > {{alias}}( arr, 2, opts, predicate, done )
    147     3000
    148     2500
    149     1000
    150     false
    151 
    152 
    153 {{alias}}.factory( [options,] predicate )
    154     Returns a function which tests whether a collection contains at least `n`
    155     elements which pass a test implemented by a predicate function.
    156 
    157     Parameters
    158     ----------
    159     options: Object (optional)
    160         Function options.
    161 
    162     options.limit: integer (optional)
    163         Maximum number of pending invocations. Default: Infinity.
    164 
    165     options.series: boolean (optional)
    166         Boolean indicating whether to process each collection element
    167         sequentially. Default: false.
    168 
    169     options.thisArg: any (optional)
    170         Execution context.
    171 
    172     predicate: Function
    173         The test function to invoke for each element in a collection.
    174 
    175     Returns
    176     -------
    177     out: Function
    178         A function which tests each element in a collection.
    179 
    180     Examples
    181     --------
    182     > function predicate( value, next ) {
    183     ...     setTimeout( onTimeout, value );
    184     ...     function onTimeout() {
    185     ...         console.log( value );
    186     ...         next( null, false );
    187     ...     }
    188     ... };
    189     > var opts = { 'series': true };
    190     > var f = {{alias}}.factory( opts, predicate );
    191     > function done( error, bool ) {
    192     ...     if ( error ) {
    193     ...         throw error;
    194     ...     }
    195     ...     console.log( bool );
    196     ... };
    197     > var arr = [ 3000, 2500, 1000 ];
    198     > f( arr, 2, done )
    199     3000
    200     2500
    201     1000
    202     false
    203     > arr = [ 2000, 1500, 1000 ];
    204     > f( arr, 2, done )
    205     2000
    206     1500
    207     1000
    208     false
    209 
    210     See Also
    211     --------
    212