time-to-botec

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

repl.txt (2141B)


      1 
      2 {{alias}}( ...f )
      3     Function composition.
      4 
      5     Returns a composite function. Starting from the right, the composite
      6     function evaluates each function and passes the result as the first argument
      7     of the next function. The result of the leftmost function is the result
      8     of the whole.
      9 
     10     The last argument for each provided function is a `next` callback which
     11     should be invoked upon function completion. The callback accepts two
     12     arguments:
     13 
     14     - `error`: error argument
     15     - `result`: function result
     16 
     17     If a composed function calls the `next` callback with a truthy `error`
     18     argument, the composite function suspends execution and immediately calls
     19     the `done` callback for subsequent `error` handling.
     20 
     21     Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
     22     wrap the `done` callback in a function which either executes at the end of
     23     the current stack (e.g., `nextTick`) or during a subsequent turn of the
     24     event loop (e.g., `setImmediate`, `setTimeout`).
     25 
     26     Only the rightmost function is explicitly permitted to accept multiple
     27     arguments. All other functions are evaluated as binary functions.
     28 
     29     The function will throw if provided fewer than two input arguments.
     30 
     31     Parameters
     32     ----------
     33     f: ...Function
     34         Functions to compose.
     35 
     36     Returns
     37     -------
     38     out: Function
     39         Composite function.
     40 
     41     Examples
     42     --------
     43     > function a( x, next ) {
     44     ...    setTimeout( onTimeout, 0 );
     45     ...    function onTimeout() {
     46     ...        next( null, 2*x );
     47     ...    }
     48     ... };
     49     > function b( x, next ) {
     50     ...    setTimeout( onTimeout, 0 );
     51     ...    function onTimeout() {
     52     ...        next( null, x+3 );
     53     ...    }
     54     ... };
     55     > function c( x, next ) {
     56     ...    setTimeout( onTimeout, 0 );
     57     ...    function onTimeout() {
     58     ...        next( null, x/5 );
     59     ...    }
     60     ... };
     61     > var f = {{alias}}( c, b, a );
     62     > function done( error, result ) {
     63     ...    if ( error ) {
     64     ...        throw error;
     65     ...    }
     66     ...    console.log( result );
     67     ... };
     68     > f( 6, done )
     69     3
     70 
     71     See Also
     72     --------
     73