source: node_modules/ramda/src/pipeWith.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1var _arity =
2/*#__PURE__*/
3require("./internal/_arity.js");
4
5var _curry2 =
6/*#__PURE__*/
7require("./internal/_curry2.js");
8
9var head =
10/*#__PURE__*/
11require("./head.js");
12
13var _reduce =
14/*#__PURE__*/
15require("./internal/_reduce.js");
16
17var tail =
18/*#__PURE__*/
19require("./tail.js");
20
21var identity =
22/*#__PURE__*/
23require("./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
50var 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
66module.exports = pipeWith;
Note: See TracBrowser for help on using the repository browser.