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