您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

37 行
1.1 KiB

4 年前
  1. import _curry1 from "./internal/_curry1.js";
  2. import nAry from "./nAry.js";
  3. /**
  4. * Wraps a function of any arity (including nullary) in a function that accepts
  5. * exactly 2 parameters. Any extraneous parameters will not be passed to the
  6. * supplied function.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.2.0
  11. * @category Function
  12. * @sig (* -> c) -> (a, b -> c)
  13. * @param {Function} fn The function to wrap.
  14. * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
  15. * arity 2.
  16. * @see R.nAry, R.unary
  17. * @example
  18. *
  19. * const takesThreeArgs = function(a, b, c) {
  20. * return [a, b, c];
  21. * };
  22. * takesThreeArgs.length; //=> 3
  23. * takesThreeArgs(1, 2, 3); //=> [1, 2, 3]
  24. *
  25. * const takesTwoArgs = R.binary(takesThreeArgs);
  26. * takesTwoArgs.length; //=> 2
  27. * // Only 2 arguments are passed to the wrapped function
  28. * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]
  29. * @symb R.binary(f)(a, b, c) = f(a, b)
  30. */
  31. var binary =
  32. /*#__PURE__*/
  33. _curry1(function binary(fn) {
  34. return nAry(2, fn);
  35. });
  36. export default binary;