UNPKG

1.15 kBJavaScriptView Raw
1var pipe =
2/*#__PURE__*/
3require("./pipe");
4
5var reverse =
6/*#__PURE__*/
7require("./reverse");
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 */
32
33
34function compose() {
35 if (arguments.length === 0) {
36 throw new Error('compose requires at least one argument');
37 }
38
39 return pipe.apply(this, reverse(arguments));
40}
41
42module.exports = compose;
\No newline at end of file