source: node_modules/ramda/es/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.5 KB
Line 
1import _arity from "./internal/_arity.js";
2import _curry2 from "./internal/_curry2.js";
3import head from "./head.js";
4import _reduce from "./internal/_reduce.js";
5import tail from "./tail.js";
6import 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
32var 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
48export default pipeWith;
Note: See TracBrowser for help on using the repository browser.