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.

32 lines
1.0 KiB

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. import _reduce from "./internal/_reduce.js";
  3. import ap from "./ap.js";
  4. import curryN from "./curryN.js";
  5. import map from "./map.js";
  6. /**
  7. * "lifts" a function to be the specified arity, so that it may "map over" that
  8. * many lists, Functions or other objects that satisfy the [FantasyLand Apply spec](https://github.com/fantasyland/fantasy-land#apply).
  9. *
  10. * @func
  11. * @memberOf R
  12. * @since v0.7.0
  13. * @category Function
  14. * @sig Number -> (*... -> *) -> ([*]... -> [*])
  15. * @param {Function} fn The function to lift into higher context
  16. * @return {Function} The lifted function.
  17. * @see R.lift, R.ap
  18. * @example
  19. *
  20. * const madd3 = R.liftN(3, (...args) => R.sum(args));
  21. * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
  22. */
  23. var liftN =
  24. /*#__PURE__*/
  25. _curry2(function liftN(arity, fn) {
  26. var lifted = curryN(arity, fn);
  27. return curryN(arity, function () {
  28. return _reduce(ap, map(lifted, arguments[0]), Array.prototype.slice.call(arguments, 1));
  29. });
  30. });
  31. export default liftN;