time-to-botec

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

repl.txt (5319B)


      1 
      2 {{alias}}( obj, [options,] transform, done )
      3     Maps values from one object to a new object having the same keys.
      4 
      5     When invoked, `transform` is provided a maximum of four arguments:
      6 
      7     - `value`: object value corresponding to `key`
      8     - `key`: object key
      9     - `obj`: the input object
     10     - `next`: a callback to be invoked after processing an object `value`
     11 
     12     The actual number of provided arguments depends on function length. If
     13     `transform` accepts two arguments, `transform` is provided:
     14 
     15     - `value`
     16     - `next`
     17 
     18     If `transform` accepts three arguments, `transform` is provided:
     19 
     20     - `value`
     21     - `key`
     22     - `next`
     23 
     24     For every other `transform` signature, `transform` is provided all four
     25     arguments.
     26 
     27     The `next` callback accepts two arguments:
     28 
     29     - `error`: error argument
     30     - `value`: transformed value
     31 
     32     If a `transform` function calls the `next` callback with a truthy `error`
     33     argument, the function suspends execution and immediately calls the `done`
     34     callback for subsequent `error` handling.
     35 
     36     Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
     37     wrap the `done` callback in a function which either executes at the end of
     38     the current stack (e.g., `nextTick`) or during a subsequent turn of the
     39     event loop (e.g., `setImmediate`, `setTimeout`).
     40 
     41     The function only maps values from own properties. Hence, the function does
     42     not map inherited properties.
     43 
     44     The function shallow copies key values.
     45 
     46     Key iteration and insertion order are *not* guaranteed.
     47 
     48     Parameters
     49     ----------
     50     obj: Object
     51         Source object.
     52 
     53     options: Object (optional)
     54         Function options.
     55 
     56     options.limit: integer (optional)
     57         Maximum number of pending invocations. Default: Infinity.
     58 
     59     options.series: boolean (optional)
     60         Boolean indicating whether to process each property sequentially.
     61         Default: false.
     62 
     63     options.thisArg: any (optional)
     64         Execution context.
     65 
     66     transform: Function
     67         Transform function. Return values are the key values of the output
     68         object.
     69 
     70     done: Function
     71         A callback invoked either upon processing all own properties or upon
     72         encountering an error.
     73 
     74     Examples
     75     --------
     76     // Basic usage:
     77     > function transform( value, key, next ) {
     78     ...     setTimeout( onTimeout, value );
     79     ...     function onTimeout() {
     80     ...         next( null, key+':'+value );
     81     ...     }
     82     ... };
     83     > function done( error, out ) {
     84     ...     if ( error ) {
     85     ...         throw error;
     86     ...     }
     87     ...     console.log( out );
     88     ... };
     89     > var obj = { 'a': 1, 'b': 2 };
     90     > {{alias}}( obj, transform, done )
     91     { 'a': 'a:1', 'b': 'b:2' }
     92 
     93     // Limit number of concurrent invocations:
     94     > function transform( value, key, next ) {
     95     ...     setTimeout( onTimeout, value );
     96     ...     function onTimeout() {
     97     ...         next( null, key+':'+value );
     98     ...     }
     99     ... };
    100     > function done( error, out ) {
    101     ...     if ( error ) {
    102     ...         throw error;
    103     ...     }
    104     ...     console.log( out );
    105     ... };
    106     > var opts = { 'limit': 2 };
    107     > var obj = { 'a': 1, 'b': 2, 'c': 3 };
    108     > {{alias}}( obj, opts, transform, done )
    109     { 'a': 'a:1', 'b': 'b:2', 'c': 'c:3' }
    110 
    111     // Process sequentially:
    112     > function transform( value, key, next ) {
    113     ...     setTimeout( onTimeout, value );
    114     ...     function onTimeout() {
    115     ...         next( null, key+':'+value );
    116     ...     }
    117     ... };
    118     > function done( error, out ) {
    119     ...     if ( error ) {
    120     ...         throw error;
    121     ...     }
    122     ...     console.log( out );
    123     ... };
    124     > var opts = { 'series': true };
    125     > var obj = { 'a': 1, 'b': 2, 'c': 3 };
    126     > {{alias}}( obj, opts, transform, done )
    127     { 'a': 'a:1', 'b': 'b:2', 'c': 'c:3' }
    128 
    129 
    130 {{alias}}.factory( [options,] transform )
    131     Returns a function which maps values from one object to a new object having
    132     the same keys.
    133 
    134     Parameters
    135     ----------
    136     options: Object (optional)
    137         Function options.
    138 
    139     options.limit: integer (optional)
    140         Maximum number of pending invocations. Default: Infinity.
    141 
    142     options.series: boolean (optional)
    143         Boolean indicating whether to process each property sequentially.
    144         Default: false.
    145 
    146     options.thisArg: any (optional)
    147         Execution context.
    148 
    149     transform: Function
    150         Transform function. Return values are the key values of the output
    151         object.
    152 
    153     Returns
    154     -------
    155     out: Function
    156         A function which maps values from one object to a new object having the
    157         same keys.
    158 
    159     Examples
    160     --------
    161     > function transform( value, key, next ) {
    162     ...     setTimeout( onTimeout, value );
    163     ...     function onTimeout() {
    164     ...         next( null, key+':'+value );
    165     ...     }
    166     ... };
    167     > var opts = { 'series': true };
    168     > var f = {{alias}}.factory( opts, transform );
    169     > function done( error, out ) {
    170     ...     if ( error ) {
    171     ...         throw error;
    172     ...     }
    173     ...     console.log( out );
    174     ... };
    175     > var obj = { 'a': 1, 'b': 2, 'c': 3 };
    176     > f( obj, done )
    177     { 'a': 'a:1', 'b': 'b:2', 'c': 'c:3' }
    178     > obj = { 'beep': 'boop' };
    179     > f( obj, done )
    180     { 'beep': 'beep:boop' }
    181 
    182     See Also
    183     --------
    184