You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1006 B

4 years ago
  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. */
  28. export default function pipe() {
  29. if (arguments.length === 0) {
  30. throw new Error('pipe requires at least one argument');
  31. }
  32. return _arity(arguments[0].length, reduce(_pipe, arguments[0], tail(arguments)));
  33. }