{"id":17729276,"url":"https://github.com/p7g/some-functional-functions","last_synced_at":"2025-03-31T17:27:21.874Z","repository":{"id":57366054,"uuid":"139274099","full_name":"p7g/some-functional-functions","owner":"p7g","description":"some haskell-wannabe functions in JS (typescript)","archived":false,"fork":false,"pushed_at":"2018-08-26T18:05:12.000Z","size":532,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-14T11:20:56.949Z","etag":null,"topics":["functional-programming","javascript","typescript"],"latest_commit_sha":null,"homepage":"https://ging0044.github.io/some-functional-functions/","language":"TypeScript","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/p7g.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-06-30T19:20:45.000Z","updated_at":"2018-08-26T18:05:13.000Z","dependencies_parsed_at":"2022-08-23T20:10:34.542Z","dependency_job_id":null,"html_url":"https://github.com/p7g/some-functional-functions","commit_stats":null,"previous_names":["ging0044/func"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p7g%2Fsome-functional-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p7g%2Fsome-functional-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p7g%2Fsome-functional-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p7g%2Fsome-functional-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p7g","download_url":"https://codeload.github.com/p7g/some-functional-functions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246507738,"owners_count":20788880,"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":["functional-programming","javascript","typescript"],"created_at":"2024-10-25T21:06:17.709Z","updated_at":"2025-03-31T17:27:21.841Z","avatar_url":"https://github.com/p7g.png","language":"TypeScript","readme":"# some-functional-functions\nsome haskell-wannabe functions in JS (typescript)\n\n## getting started\n1. import the module:\n```js\nimport { func, pipe, compose } from \"func\";\n// OR\nconst func = require(\"func\");\n```\n2. use the stuff:\n```js\nconst log = func((a, b, c) =\u003e console.log(a, b, c));\nlog(\"Wooa\")(\"aaahh\")(\"!\");\n// Wooa aaahh !\n```\n\n## the functions\n\nSee [here](https://ging0044.github.io/some-functional-functions/) for more up-to-date documentation.\n\n### `func`\nMakes a function curried. Pretty cool stuff.\n\nIt takes a function, and optionally the number of args. Use the second parameter if it's a function that takes as many args as you put.\n\n```js\nconst log1 = func((a, b, c) =\u003e console.log(a, b, c));\nconst log2 = func(console.log, 3);\n```\n\n### `pipe`\nPipes the output of each function into the next.\n\nThe first function can take as many args as you want, but after that they should only take one. You can do some fun stuff if you use `func()` to make the functions to pass into `pipe()`, but keep in mind you'll be dealing with partially applied functions at that point.\n\n```js\nconst doSomeStuff = pipe(\n  x =\u003e x * 2,\n  x =\u003e x ** 2,\n  x =\u003e x.toString()\n);\n\nconsole.log(doSomeStuff(3));\n// \"36\"\n```\n\n### `compose`\nSame thing as pipe, but right to left. Like some fancy math stuff.\n\n```js\nconst doSomeStuff = compose(\n  x =\u003e x.toString(),\n  x =\u003e x ** 2,\n  x =\u003e x * 2\n);\n\nconsole.log(doSomeStuff(3));\n// \"36\"\n```\n\n### `flip`\nTakes a function that takes 2 arguments (or more) and flips the first 2 arguments.\n\n```js\nconst flipped = flip((x, y) =\u003e `${x}, ${y}`);\n\nconsole.log(flipped(1, 2));\n// \"2, 1\"\n```\n\n### `map`\nMaps an array to a function\n\n```js\nconst times2 = map(x =\u003e x * 2);\n\nconsole.log(times2([1, 2, 3, 4, 5]));\n// [2, 4, 6, 8, 10]\n```\n\n### `foldl`\nFolds (reduces) an array from the left.\n\n```js\nconst sum = foldl((acc, x) =\u003e acc + x, 0);\n\nconsole.log(sum([1, 2, 3]));\n\n// 6\n```\n\n### `foldr`\nFolds (reduces) an array from the right. Note that the reducer takes the item first, then the accumulator, then the index. It's like haskell!!!!!\n\n```js\nconst div = foldr((x, acc) =\u003e x / acc, 1);\n\nconsole.log(div([1, 2, 3, 4, 5]));\n// 1.875\n// this is equivalent to 1/(2/(3/(4/(5/1)))), not 1/2/3/4/5/1\n```\n\n### `reverse`\nReverses an array.\n\n```js\nconsole.log(reverse([1, 2, 3, 4, 5]));\n// [5, 4, 3, 2, 1]\n```\n\n### `listc`\nList comprehensions. Coming soon. Maybe.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp7g%2Fsome-functional-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp7g%2Fsome-functional-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp7g%2Fsome-functional-functions/lists"}