UNPKG

1.07 kBJavaScriptView Raw
1var _arity =
2/*#__PURE__*/
3require("./internal/_arity");
4
5var _pipe =
6/*#__PURE__*/
7require("./internal/_pipe");
8
9var reduce =
10/*#__PURE__*/
11require("./reduce");
12
13var tail =
14/*#__PURE__*/
15require("./tail");
16/**
17 * Performs left-to-right function composition. The first argument may have
18 * any arity; the remaining arguments must be unary.
19 *
20 * In some libraries this function is named `sequence`.
21 *
22 * **Note:** The result of pipe is not automatically curried.
23 *
24 * @func
25 * @memberOf R
26 * @since v0.1.0
27 * @category Function
28 * @sig (((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> ((a, b, ..., n) -> z)
29 * @param {...Function} functions
30 * @return {Function}
31 * @see R.compose
32 * @example
33 *
34 * const f = R.pipe(Math.pow, R.negate, R.inc);
35 *
36 * f(3, 4); // -(3^4) + 1
37 * @symb R.pipe(f, g, h)(a, b) = h(g(f(a, b)))
38 */
39
40
41function pipe() {
42 if (arguments.length === 0) {
43 throw new Error('pipe requires at least one argument');
44 }
45
46 return _arity(arguments[0].length, reduce(_pipe, arguments[0], tail(arguments)));
47}
48
49module.exports = pipe;
\No newline at end of file