main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | var _arity =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_arity.js");
|
---|
| 4 |
|
---|
| 5 | var _pipe =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_pipe.js");
|
---|
| 8 |
|
---|
| 9 | var reduce =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./reduce.js");
|
---|
| 12 |
|
---|
| 13 | var tail =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./tail.js");
|
---|
| 16 | /**
|
---|
| 17 | * Performs left-to-right function composition. The first argument may have
|
---|
| 18 | * any arity; the remaining arguments must be unary.
|
---|
| 19 | *
|
---|
| 20 | * In some libraries this function is named `sequence`.
|
---|
| 21 | *
|
---|
| 22 | * **Note:** The result of pipe is not automatically curried.
|
---|
| 23 | *
|
---|
| 24 | * @func
|
---|
| 25 | * @memberOf R
|
---|
| 26 | * @since v0.1.0
|
---|
| 27 | * @category Function
|
---|
| 28 | * @sig (((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> ((a, b, ..., n) -> z)
|
---|
| 29 | * @param {...Function} functions
|
---|
| 30 | * @return {Function}
|
---|
| 31 | * @see R.compose
|
---|
| 32 | * @example
|
---|
| 33 | *
|
---|
| 34 | * const f = R.pipe(Math.pow, R.negate, R.inc);
|
---|
| 35 | *
|
---|
| 36 | * f(3, 4); // -(3^4) + 1
|
---|
| 37 | * @symb R.pipe(f, g, h)(a, b) = h(g(f(a, b)))
|
---|
| 38 | * @symb R.pipe(f, g, h)(a)(b) = h(g(f(a)))(b)
|
---|
| 39 | */
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | function pipe() {
|
---|
| 43 | if (arguments.length === 0) {
|
---|
| 44 | throw new Error('pipe requires at least one argument');
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | return _arity(arguments[0].length, reduce(_pipe, arguments[0], tail(arguments)));
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | module.exports = pipe; |
---|
Note:
See
TracBrowser
for help on using the repository browser.