time-to-botec

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

README.md (3249B)


      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 # papplyRight
     22 
     23 > Partially apply function arguments from the right.
     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 papplyRight = require( '@stdlib/utils/papply-right' );
     41 ```
     42 
     43 #### papplyRight( fcn\[, ...args] )
     44 
     45 Partially applies function arguments from the right.
     46 
     47 ```javascript
     48 function say( text, name ) {
     49     return text + ', ' + name + '.';
     50 }
     51 
     52 var toSusan = papplyRight( say, 'Susan B. Anthony' );
     53 
     54 var str = toSusan( 'Thank you' );
     55 // returns 'Thank you, Susan B. Anthony.'
     56 
     57 str = toSusan( 'Never forget' );
     58 // returns 'Never forget, Susan B. Anthony.'
     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 -   The difference between this function and [`papply`][@stdlib/utils/papply] is the order in which arguments are applied. This function fixes the rightmost arguments.
     74 
     75 </section>
     76 
     77 <!-- /.notes -->
     78 
     79 <!-- Package usage examples. -->
     80 
     81 <section class="examples">
     82 
     83 ## Examples
     84 
     85 <!-- eslint no-undef: "error" -->
     86 
     87 ```javascript
     88 var randu = require( '@stdlib/random/base/randu' );
     89 var floor = require( '@stdlib/math/base/special/floor' );
     90 var papplyRight = require( '@stdlib/utils/papply-right' );
     91 
     92 var fcn;
     93 var x;
     94 var y;
     95 var z;
     96 var v;
     97 var i;
     98 
     99 function add( x, y, z, w, t, s ) {
    100     return x + y + z + w + t + s;
    101 }
    102 
    103 fcn = papplyRight( add, 5, 4, 3 );
    104 
    105 for ( i = 0; i < 100; i++ ) {
    106     x = floor( randu() * 5 );
    107     y = floor( randu() * 10 );
    108     z = floor( randu() * 15 );
    109     v = fcn( x, y, z );
    110     console.log( '%d+%d+%d+5+4+3 = %d', x, y, z, v );
    111 }
    112 ```
    113 
    114 </section>
    115 
    116 <!-- /.examples -->
    117 
    118 <!-- 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. -->
    119 
    120 <section class="references">
    121 
    122 </section>
    123 
    124 <!-- /.references -->
    125 
    126 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    127 
    128 <section class="links">
    129 
    130 [@stdlib/utils/papply]: https://www.npmjs.com/package/@stdlib/utils/tree/main/papply
    131 
    132 </section>
    133 
    134 <!-- /.links -->