time-to-botec

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

README.md (2788B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # papply
     22 
     23 > Partially apply function arguments.
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var papply = require( '@stdlib/utils/papply' );
     41 ```
     42 
     43 #### papply( fcn\[, ...args] )
     44 
     45 Partially applies function arguments.
     46 
     47 ```javascript
     48 function add( x, y ) {
     49     return x + y;
     50 }
     51 
     52 var add2 = papply( add, 2 );
     53 
     54 var sum = add2( 3 );
     55 // returns 5
     56 
     57 sum = add2( 7 );
     58 // returns 9
     59 ```
     60 
     61 </section>
     62 
     63 <!-- /.usage -->
     64 
     65 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     66 
     67 <section class="notes">
     68 
     69 ## Notes
     70 
     71 -   The implementation does **not** set the `length` of the returned function. Accordingly, the returned function `length` is **always** `0`.
     72 -   The evaluation context is **always** `null`.
     73 
     74 </section>
     75 
     76 <!-- /.notes -->
     77 
     78 <!-- Package usage examples. -->
     79 
     80 <section class="examples">
     81 
     82 ## Examples
     83 
     84 <!-- eslint no-undef: "error" -->
     85 
     86 ```javascript
     87 var randu = require( '@stdlib/random/base/randu' );
     88 var floor = require( '@stdlib/math/base/special/floor' );
     89 var papply = require( '@stdlib/utils/papply' );
     90 
     91 var fcn;
     92 var w;
     93 var t;
     94 var s;
     95 var v;
     96 var i;
     97 
     98 function add( x, y, z, w, t, s ) {
     99     return x + y + z + w + t + s;
    100 }
    101 
    102 fcn = papply( add, 5, 4, 3 );
    103 
    104 for ( i = 0; i < 100; i++ ) {
    105     w = floor( randu() * 5 );
    106     t = floor( randu() * 10 );
    107     s = floor( randu() * 15 );
    108     v = fcn( w, t, s );
    109     console.log( '5+4+3+%d+%d+%d = %d', w, t, s, v );
    110 }
    111 ```
    112 
    113 </section>
    114 
    115 <!-- /.examples -->
    116 
    117 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    118 
    119 <section class="references">
    120 
    121 </section>
    122 
    123 <!-- /.references -->
    124 
    125 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    126 
    127 <section class="links">
    128 
    129 </section>
    130 
    131 <!-- /.links -->