README.md (3195B)
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 # funseq 22 23 > Function sequence. 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 funseq = require( '@stdlib/utils/function-sequence' ); 41 ``` 42 43 #### funseq( ...fcn ) 44 45 Returns a pipeline function. Starting from the left, the pipeline function evaluates each function and passes the result as an argument to the next function. The result of the rightmost function is the result of the whole. 46 47 ```javascript 48 function a( x ) { 49 return 2 * x; 50 } 51 52 function b( x ) { 53 return x + 3; 54 } 55 56 function c( x ) { 57 return x / 5; 58 } 59 60 var f = funseq( a, b, c ); 61 62 var z = f( 6 ); // ((2*x)+3)/5 63 // returns 3 64 ``` 65 66 **Only** the leftmost function is explicitly permitted to accept multiple arguments. All other functions are evaluated as **unary** functions. 67 68 ```javascript 69 function a( x, y ) { 70 return (x*5) + (y*3); 71 } 72 73 function b( r ) { 74 return r + 12; 75 } 76 77 var f = funseq( a, b ); 78 79 var z = f( 4, 6 ); 80 // returns 50 81 ``` 82 83 </section> 84 85 <!-- /.usage --> 86 87 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 88 89 <section class="notes"> 90 91 ## Notes 92 93 - The function will throw if provided fewer than `2` input arguments. 94 - The difference between this function and [`compose`][@stdlib/utils/compose] is that this function evaluates input arguments from left-to-right, rather than right-to-left. 95 96 </section> 97 98 <!-- /.notes --> 99 100 <!-- Package usage examples. --> 101 102 <section class="examples"> 103 104 ## Examples 105 106 <!-- eslint no-undef: "error" --> 107 108 ```javascript 109 var funseq = require( '@stdlib/utils/function-sequence' ); 110 111 function a( x, y ) { 112 return x * y; 113 } 114 115 function b( z ) { 116 return z + 5; 117 } 118 119 function c( r ) { 120 return r / 10; 121 } 122 123 var f = funseq( a, b, c ); 124 125 var v = f( 5, 3 ); 126 // returns 2 127 ``` 128 129 </section> 130 131 <!-- /.examples --> 132 133 <!-- 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. --> 134 135 <section class="references"> 136 137 </section> 138 139 <!-- /.references --> 140 141 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 142 143 <section class="links"> 144 145 [@stdlib/utils/compose]: https://www.npmjs.com/package/@stdlib/utils/tree/main/compose 146 147 </section> 148 149 <!-- /.links -->