{"id":13549267,"url":"https://github.com/dominictarr/curry","last_synced_at":"2025-04-02T22:31:34.748Z","repository":{"id":1209046,"uuid":"1121569","full_name":"dominictarr/curry","owner":"dominictarr","description":"simple curry module, with nothing *too clever*, and full test coverage","archived":true,"fork":false,"pushed_at":"2019-10-08T05:42:09.000Z","size":39,"stargazers_count":312,"open_issues_count":14,"forks_count":19,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-29T21:51:34.810Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dominictarr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-11-29T08:55:50.000Z","updated_at":"2024-10-02T17:03:04.000Z","dependencies_parsed_at":"2022-08-16T12:35:21.171Z","dependency_job_id":null,"html_url":"https://github.com/dominictarr/curry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fcurry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fcurry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fcurry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fcurry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominictarr","download_url":"https://codeload.github.com/dominictarr/curry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246905120,"owners_count":20852812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:20.055Z","updated_at":"2025-04-02T22:31:34.429Z","avatar_url":"https://github.com/dominictarr.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Modules","模块"],"sub_categories":["Function","函数"],"readme":"CURRY\n=====\n\nA curry function without anything **too clever**\n_(... because hunger is the finest spice)_\n\n[![browser support](https://ci.testling.com/hughfdjackson/curry.png)](https://ci.testling.com/hughfdjackson/curry)\n\n\n# Why\n\nIf you don't know currying, or aren't sold on it's awesomeness, perhaps [a friendly blog post](http://hughfdjackson.com/javascript/2013/07/06/why-curry-helps/) will help.\n\n\n# API\n\n### curry\n\n```javascript\nvar curry = require('curry');\n\n//-- creating a curried function is pretty\n//-- straight forward:\nvar add = curry(function(a, b){ return a + b });\n\n//-- it can be called like normal:\nadd(1, 2) //= 3\n\n//-- or, if you miss off any arguments,\n//-- a new funtion that expects all (or some) of\n//-- the remaining arguments will be created:\nvar add1 = add(1);\nadd1(2) //= 3;\n\n//-- curry knows how many arguments a function should take\n//-- by the number of parameters in the parameter list\n\n//-- in this case, a function and two arrays is expected\n//-- (fn, a, b).  zipWith will combine two arrays using a function:\nvar zipWith = curry(function(fn, a, b){\n    return a.map(function(val, i){ return fn(val, b[i]) });\n});\n\n//-- if there are still more arguments required, a curried function\n//-- will always return a new curried function:\nvar zipAdd = zipWith(add);\nvar zipAddWith123 = zipAdd([1, 2, 3]);\n\n//-- both functions are usable as you'd expect at any time:\nzipAdd([1, 2, 3], [1, 2, 3]); //= [2, 4, 6]\nzipAddWith123([5, 6, 7]); //= [6, 8, 10]\n\n//-- the number of arguments a function is expected to provide\n//-- can be discovered by the .length property\nzipWith.length; //= 3\nzipAdd.length; //= 2\nzipAddWith123.length; //= 1\n```\n\n### curry.to\n\nSometimes it's necessary (especially when wrapping variadic functions) to explicitly provide an arity for your curried function:\n\n```javascript\nvar sum = function(){\n\tvar nums = [].slice.call(arguments);\n\treturn nums.reduce(function(a, b){ return a + b });\n}\n\nvar sum3 = curry.to(3, sum);\nvar sum4 = curry.to(4, sum);\n\nsum3(1, 2)(3) //= 6\nsum4(1)(2)(3, 4) //= 10\n```\n\n### curry.adapt\n\nIt's a (sad?) fact that JavaScript functions are often written to take the 'context' object as the first argument.\n\nWith curried functions, of course, we want it to be the last object.  `curry.adapt` shifts the context to the last argument,\nto give us a hand with this:\n\n```javascript\nvar delve = require('delve');\nvar delveC = curry.adapt(delve);\n\nvar getDataFromResponse = delveC('response.body.data');\ngetDataFromResponse({ response: { body: { data: { x: 2 }} } }); //= { x: 2 }\n```\n\n### curry.adaptTo\n\nLike `curry.adapt`, but the arity explicitly provided:\n\n```javascript\nvar _ = require('lodash');\nvar map = curry.adaptTo(2, _.map);\nvar mapInc = map(function(a){ return a + 1 })\n\nmapInc([1, 2, 3]) //= [2, 3, 4]\n```\n\n# installation\n\n### node/npm\n\n```bash\nnpm install curry\n```\n\n### amd\n\n```javascript\ndefine(['libs/curry.min'], function(curry){\n    //-- assuming libs/curry.min.js is the downloaded minified version from this repo,\n    //-- curry will be available here\n});\n```\n\n### browser\n\nIf you're not using tools like [browserify](https://github.com/substack/node-browserify) or [require.js](http://requirejs.org), you can load curry globally:\n```html\n\u003cscript src=\"libs/curry.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    \u003c!-- curry available here --\u003e\n\u003c/script\u003e\n```\n∏∏\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictarr%2Fcurry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominictarr%2Fcurry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictarr%2Fcurry/lists"}