1 | var pipe =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./pipe.js");
|
---|
4 |
|
---|
5 | var reverse =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./reverse.js");
|
---|
8 | /**
|
---|
9 | * Performs right-to-left function composition. The last argument may have
|
---|
10 | * any arity; the remaining arguments must be unary.
|
---|
11 | *
|
---|
12 | * **Note:** The result of compose is not automatically curried.
|
---|
13 | *
|
---|
14 | * @func
|
---|
15 | * @memberOf R
|
---|
16 | * @since v0.1.0
|
---|
17 | * @category Function
|
---|
18 | * @sig ((y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)) -> ((a, b, ..., n) -> z)
|
---|
19 | * @param {...Function} ...functions The functions to compose
|
---|
20 | * @return {Function}
|
---|
21 | * @see R.pipe
|
---|
22 | * @example
|
---|
23 | *
|
---|
24 | * const classyGreeting = (firstName, lastName) => "The name's " + lastName + ", " + firstName + " " + lastName
|
---|
25 | * const yellGreeting = R.compose(R.toUpper, classyGreeting);
|
---|
26 | * yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND"
|
---|
27 | *
|
---|
28 | * R.compose(Math.abs, R.add(1), R.multiply(2))(-4) //=> 7
|
---|
29 | *
|
---|
30 | * @symb R.compose(f, g, h)(a, b) = f(g(h(a, b)))
|
---|
31 | * @symb R.compose(f, g, h)(a)(b) = f(g(h(a)))(b)
|
---|
32 | */
|
---|
33 |
|
---|
34 |
|
---|
35 | function compose() {
|
---|
36 | if (arguments.length === 0) {
|
---|
37 | throw new Error('compose requires at least one argument');
|
---|
38 | }
|
---|
39 |
|
---|
40 | return pipe.apply(this, reverse(arguments));
|
---|
41 | }
|
---|
42 |
|
---|
43 | module.exports = compose; |
---|