main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d24f17c] | 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 1 parameter. 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 (a -> b -> c -> ... -> z) -> (a -> z)
|
---|
| 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 1.
|
---|
| 16 | * @see R.binary, R.nAry
|
---|
| 17 | * @example
|
---|
| 18 | *
|
---|
| 19 | * const takesTwoArgs = function(a, b) {
|
---|
| 20 | * return [a, b];
|
---|
| 21 | * };
|
---|
| 22 | * takesTwoArgs.length; //=> 2
|
---|
| 23 | * takesTwoArgs(1, 2); //=> [1, 2]
|
---|
| 24 | *
|
---|
| 25 | * const takesOneArg = R.unary(takesTwoArgs);
|
---|
| 26 | * takesOneArg.length; //=> 1
|
---|
| 27 | * // Only 1 argument is passed to the wrapped function
|
---|
| 28 | * takesOneArg(1, 2); //=> [1, undefined]
|
---|
| 29 | * @symb R.unary(f)(a, b, c) = f(a)
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | var unary =
|
---|
| 33 | /*#__PURE__*/
|
---|
| 34 | _curry1(function unary(fn) {
|
---|
| 35 | return nAry(1, fn);
|
---|
| 36 | });
|
---|
| 37 |
|
---|
| 38 | export default unary; |
---|
Note:
See
TracBrowser
for help on using the repository browser.