{"id":29269110,"url":"https://github.com/bary12/lofunc","last_synced_at":"2025-07-04T20:07:29.854Z","repository":{"id":57290571,"uuid":"118172793","full_name":"bary12/lofunc","owner":"bary12","description":"a Javascript higher-order functional programming library which aims to make functional programming in Javascript better.","archived":false,"fork":false,"pushed_at":"2018-03-23T12:42:17.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-27T21:02:36.444Z","etag":null,"topics":["javascript","javascript-library","javascript-utility","lodash","utility","utility-library"],"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/bary12.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":"2018-01-19T20:06:58.000Z","updated_at":"2023-12-05T06:56:05.000Z","dependencies_parsed_at":"2022-08-28T05:52:38.803Z","dependency_job_id":null,"html_url":"https://github.com/bary12/lofunc","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/bary12/lofunc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bary12%2Flofunc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bary12%2Flofunc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bary12%2Flofunc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bary12%2Flofunc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bary12","download_url":"https://codeload.github.com/bary12/lofunc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bary12%2Flofunc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263611900,"owners_count":23488429,"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":["javascript","javascript-library","javascript-utility","lodash","utility","utility-library"],"created_at":"2025-07-04T20:07:29.175Z","updated_at":"2025-07-04T20:07:29.841Z","avatar_url":"https://github.com/bary12.png","language":"JavaScript","readme":"# Lofunc\n\nLofunc is a higher-order functional programming library. It manipulates functions. It aims to make functional programming in Javascript better.\n\n## install\n\nwith npm\n\n```bash\nnpm install --save lofunc\n```\n\n\n## Examples\n\nOne of the most useful features of Lofunc is `F.object`. It returns a function that handles each of the keys of an object differently.\n\n```javascript\nimport F from 'lofunc';\n\nconst david = {\n  name: 'David',\n  age: 21\n}\n\nconst func = F.object({\n  name: name =\u003e name + ' the old',\n  age: age =\u003e age * 4\n});\n\nfunc(david); // {name: 'David the old', age: 84}\n```\n\nThe function returned by `F.object` does not mutate the object, and the properties are deep-cloned.\n\nThe `F.compose` function allows for functional composition.\n\n```javascript\n// Equivalent to x =\u003e x * 2 + 1\nconst func = F.compose(\n  x =\u003e x + 1,\n  x =\u003e x * 2\n)\n\nfunc(3); // 7\n```\n\nFor readability, `F.chain` is also provided. This just performs `F.compose` in the oposite order.\n\n```javascript\n// Equivalent to x =\u003e (x + 1) * 2\nconst func = F.chain(\n  x =\u003e x + 1,\n  x =\u003e x * 2\n)\n\nfunc(3); // 8\n```\n\nLofunc also provides curried `map` and `filter`. Currently not many curried util functions are available, and one might want to use Lofunc in combination with [lodash/fp](https://github.com/lodash/lodash/wiki/FP-Guide) or [Ramda.js](ramdajs.com).\n\n```javascript\nconst david = {\n  name: 'David',\n  cats: [\n    {\n      name: 'Dave',\n      age: 7\n    },\n    {\n      name: 'Davis',\n      age: 2\n    }\n  ]\n}\n\nconst func = F.object({\n  name: x =\u003e x + ' the cat lover',\n  cats: F.chain(\n      F.filter(cat =\u003e cat.age \u003e 5),\n      F.map(F.object({\n        name: name =\u003e name + ' the cat'\n      }))\n    )\n});\n\nfunc(david);\n/*\n{\n  name: 'David the cat lover',\n  cats: [\n    {\n      name: 'Dave the cat',\n      age: 7\n    }\n  ]\n}\n*/\n```\n\n\n## Utility functions\n\nLofunc provides utility functions, `F.spread` and `F.unspread`, which convert a function that accepts an array to a function with rest parameters and vice versa.\n\n```javascript\nfunction sum(arr) {\n  return arr.reduce((a, b) =\u003e a + b, 0);\n}\n\nF.spread(sum)(1, 2, 3); // 6\n```\n\n```javascript\nfunction addThree(a, b, c) {\n  return a + b + c;\n}\n\nF.unspread(addThree)([1, 2, 3]); // 6\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbary12%2Flofunc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbary12%2Flofunc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbary12%2Flofunc/lists"}