UNPKG

1.22 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4
5var pipeWith =
6/*#__PURE__*/
7require("./pipeWith");
8
9var reverse =
10/*#__PURE__*/
11require("./reverse");
12/**
13 * Performs right-to-left function composition using transforming function. The last argument may have
14 * any arity; the remaining arguments must be unary.
15 *
16 * **Note:** The result of compose is not automatically curried. Transforming function is not used on the
17 * last argument.
18 *
19 * @func
20 * @memberOf R
21 * @since v0.26.0
22 * @category Function
23 * @sig ((* -> *), [(y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)]) -> ((a, b, ..., n) -> z)
24 * @param {...Function} ...functions The functions to compose
25 * @return {Function}
26 * @see R.compose, R.pipeWith
27 * @example
28 *
29 * const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res));
30 *
31 * composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2
32 * composeWhileNotNil([R.inc, R.prop('age')])({}) //=> undefined
33 *
34 * @symb R.composeWith(f)([g, h, i])(...args) = f(g, f(h, i(...args)))
35 */
36
37
38var composeWith =
39/*#__PURE__*/
40_curry2(function composeWith(xf, list) {
41 return pipeWith.apply(this, [xf, reverse(list)]);
42});
43
44module.exports = composeWith;
\No newline at end of file