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
974 B

4 years ago
  1. import _curry1 from "./internal/_curry1.js";
  2. import curryN from "./curryN.js";
  3. /**
  4. * Returns a new function much like the supplied one, except that the first two
  5. * arguments' order is reversed.
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.1.0
  10. * @category Function
  11. * @sig ((a, b, c, ...) -> z) -> (b -> a -> c -> ... -> z)
  12. * @param {Function} fn The function to invoke with its first two parameters reversed.
  13. * @return {*} The result of invoking `fn` with its first two parameters' order reversed.
  14. * @example
  15. *
  16. * const mergeThree = (a, b, c) => [].concat(a, b, c);
  17. *
  18. * mergeThree(1, 2, 3); //=> [1, 2, 3]
  19. *
  20. * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3]
  21. * @symb R.flip(f)(a, b, c) = f(b, a, c)
  22. */
  23. var flip =
  24. /*#__PURE__*/
  25. _curry1(function flip(fn) {
  26. return curryN(fn.length, function (a, b) {
  27. var args = Array.prototype.slice.call(arguments, 0);
  28. args[0] = b;
  29. args[1] = a;
  30. return fn.apply(this, args);
  31. });
  32. });
  33. export default flip;