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