UNPKG

1.09 kBJavaScriptView Raw
1import _curry1 from "./internal/_curry1.js";
2import 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
32var binary =
33/*#__PURE__*/
34_curry1(function binary(fn) {
35 return nAry(2, fn);
36});
37
38export default binary;
\No newline at end of file