[d24f17c] | 1 | var _arity =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_arity.js");
|
---|
| 4 |
|
---|
| 5 | var _curry2 =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_curry2.js");
|
---|
| 8 |
|
---|
| 9 | var head =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./head.js");
|
---|
| 12 |
|
---|
| 13 | var _reduce =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./internal/_reduce.js");
|
---|
| 16 |
|
---|
| 17 | var tail =
|
---|
| 18 | /*#__PURE__*/
|
---|
| 19 | require("./tail.js");
|
---|
| 20 |
|
---|
| 21 | var identity =
|
---|
| 22 | /*#__PURE__*/
|
---|
| 23 | require("./identity.js");
|
---|
| 24 | /**
|
---|
| 25 | * Performs left-to-right function composition using transforming function. The first function may have
|
---|
| 26 | * any arity; the remaining functions must be unary.
|
---|
| 27 | *
|
---|
| 28 | * **Note:** The result of pipeWith is not automatically curried. Transforming function is not used on the
|
---|
| 29 | * first argument.
|
---|
| 30 | *
|
---|
| 31 | * @func
|
---|
| 32 | * @memberOf R
|
---|
| 33 | * @since v0.26.0
|
---|
| 34 | * @category Function
|
---|
| 35 | * @sig ((* -> *), [((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)]) -> ((a, b, ..., n) -> z)
|
---|
| 36 | * @param {Function} transformer The transforming function
|
---|
| 37 | * @param {Array} functions The functions to pipe
|
---|
| 38 | * @return {Function}
|
---|
| 39 | * @see R.composeWith, R.pipe
|
---|
| 40 | * @example
|
---|
| 41 | *
|
---|
| 42 | * const pipeWhileNotNil = R.pipeWith((f, res) => R.isNil(res) ? res : f(res));
|
---|
| 43 | * const f = pipeWhileNotNil([Math.pow, R.negate, R.inc])
|
---|
| 44 | *
|
---|
| 45 | * f(3, 4); // -(3^4) + 1
|
---|
| 46 | * @symb R.pipeWith(f)([g, h, i])(...args) = f(i, f(h, g(...args)))
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | var pipeWith =
|
---|
| 51 | /*#__PURE__*/
|
---|
| 52 | _curry2(function pipeWith(xf, list) {
|
---|
| 53 | if (list.length <= 0) {
|
---|
| 54 | return identity;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | var headList = head(list);
|
---|
| 58 | var tailList = tail(list);
|
---|
| 59 | return _arity(headList.length, function () {
|
---|
| 60 | return _reduce(function (result, f) {
|
---|
| 61 | return xf.call(this, f, result);
|
---|
| 62 | }, headList.apply(this, arguments), tailList);
|
---|
| 63 | });
|
---|
| 64 | });
|
---|
| 65 |
|
---|
| 66 | module.exports = pipeWith; |
---|