1 | import _curry2 from "./internal/_curry2.js";
|
---|
2 | import pipeWith from "./pipeWith.js";
|
---|
3 | import reverse from "./reverse.js";
|
---|
4 | /**
|
---|
5 | * Performs right-to-left function composition using transforming function. The last function may have
|
---|
6 | * any arity; the remaining functions must be unary. Unlike `compose`, functions are passed in an array.
|
---|
7 | *
|
---|
8 | * **Note:** The result of composeWith is not automatically curried. Transforming function is not used
|
---|
9 | * on the last argument.
|
---|
10 | *
|
---|
11 | * @func
|
---|
12 | * @memberOf R
|
---|
13 | * @since v0.26.0
|
---|
14 | * @category Function
|
---|
15 | * @sig ((* -> *), [(y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)]) -> ((a, b, ..., n) -> z)
|
---|
16 | * @param {Function} transformer The transforming function
|
---|
17 | * @param {Array} functions The functions to compose
|
---|
18 | * @return {Function}
|
---|
19 | * @see R.compose, R.pipeWith
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res));
|
---|
23 | *
|
---|
24 | * composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2
|
---|
25 | * composeWhileNotNil([R.inc, R.prop('age')])({}) //=> undefined
|
---|
26 | *
|
---|
27 | * @symb R.composeWith(f)([g, h, i])(...args) = f(g, f(h, i(...args)))
|
---|
28 | */
|
---|
29 |
|
---|
30 | var composeWith =
|
---|
31 | /*#__PURE__*/
|
---|
32 | _curry2(function composeWith(xf, list) {
|
---|
33 | return pipeWith.apply(this, [xf, reverse(list)]);
|
---|
34 | });
|
---|
35 |
|
---|
36 | export default composeWith; |
---|