Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on. The arity of `func` may be specified if `func.length` is not sufficient. The `curry.placeholder` value, which defaults to `_` in monolithic builds, may be used as a placeholder for provided arguments. **Note:** This method doesn't set the "length" property of curried functions.
const abc = function(a, b, c) {
return [a, b, c]
}
const curried = curry(abc)
curried(1)(2)(3)
// => [1, 2, 3]
curried(1, 2)(3)
// => [1, 2, 3]
curried(1, 2, 3)
// => [1, 2, 3]
// Curried with placeholders.
curried(1)(_, 3)(2)
// => [1, 2, 3]
Name | Type | Attribute | Description |
---|---|---|---|
func | The function to curry. | ||
arity | The arity of `func`. |
{ "comment": "/**\r\n * Creates a function that accepts arguments of `func` and either invokes\r\n * `func` returning its result, if at least `arity` number of arguments have\r\n * been provided, or returns a function that accepts the remaining `func`\r\n * arguments, and so on. The arity of `func` may be specified if `func.length`\r\n * is not sufficient.\r\n *\r\n * The `curry.placeholder` value, which defaults to `_` in monolithic builds,\r\n * may be used as a placeholder for provided arguments.\r\n *\r\n * **Note:** This method doesn't set the \"length\" property of curried functions.\r\n *\r\n * @since 2.0.0\r\n * @category Function\r\n * @param {Function} func The function to curry.\r\n * @param {number} [arity=func.length] The arity of `func`.\r\n * @returns {Function} Returns the new curried function.\r\n * @example\r\n *\r\n * const abc = function(a, b, c) {\r\n * return [a, b, c]\r\n * }\r\n *\r\n * const curried = curry(abc)\r\n *\r\n * curried(1)(2)(3)\r\n * // => [1, 2, 3]\r\n *\r\n * curried(1, 2)(3)\r\n * // => [1, 2, 3]\r\n *\r\n * curried(1, 2, 3)\r\n * // => [1, 2, 3]\r\n *\r\n * // Curried with placeholders.\r\n * curried(1)(_, 3)(2)\r\n * // => [1, 2, 3]\r\n */", "meta": { "range": [ 1253, 1458 ], "filename": "curry.js", "lineno": 44, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100000999", "name": "curry", "type": "FunctionDeclaration", "paramnames": [ "func", "arity" ] }, "vars": { "result": "curry~result", "result.placeholder": "curry~result.placeholder" } }, "description": "Creates a function that accepts arguments of `func` and either invokes\r`func` returning its result, if at least `arity` number of arguments have\rbeen provided, or returns a function that accepts the remaining `func`\rarguments, and so on. The arity of `func` may be specified if `func.length`\ris not sufficient.\r\rThe `curry.placeholder` value, which defaults to `_` in monolithic builds,\rmay be used as a placeholder for provided arguments.\r\r**Note:** This method doesn't set the \"length\" property of curried functions.", "since": "2.0.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Function", "value": "Function" } ], "params": [ { "type": { "names": [ "function" ] }, "description": "The function to curry.", "name": "func" }, { "type": { "names": [ "number" ] }, "optional": true, "defaultvalue": "func.length", "description": "The arity of `func`.", "name": "arity" } ], "returns": [ { "type": { "names": [ "function" ] }, "description": "Returns the new curried function." } ], "examples": [ "const abc = function(a, b, c) {\r return [a, b, c]\r}\r\rconst curried = curry(abc)\r\rcurried(1)(2)(3)\r// => [1, 2, 3]\r\rcurried(1, 2)(3)\r// => [1, 2, 3]\r\rcurried(1, 2, 3)\r// => [1, 2, 3]\r\r// Curried with placeholders.\rcurried(1)(_, 3)(2)\r// => [1, 2, 3]" ], "name": "curry", "longname": "curry", "kind": "function", "scope": "global", "___id": "T000002R000103", "___s": true, "filepath": "curry.js" }