{"id":16979767,"url":"https://github.com/jajaperson/copb","last_synced_at":"2026-05-16T12:32:36.212Z","repository":{"id":56714619,"uuid":"334163494","full_name":"jajaperson/copb","owner":"jajaperson","description":"A functional composition framework built for TypesScript that provides type safety without the need for the usual countless overloads, thanks to some functional type trickery.","archived":false,"fork":false,"pushed_at":"2022-08-25T08:19:58.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-26T20:07:29.391Z","etag":null,"topics":["composition","currying","functional-programming","overloading","pipes","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/copb","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jajaperson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-29T14:07:23.000Z","updated_at":"2023-04-06T09:14:07.000Z","dependencies_parsed_at":"2022-08-16T00:00:53.817Z","dependency_job_id":null,"html_url":"https://github.com/jajaperson/copb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"jajaperson/deno-mod-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jajaperson%2Fcopb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jajaperson%2Fcopb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jajaperson%2Fcopb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jajaperson%2Fcopb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jajaperson","download_url":"https://codeload.github.com/jajaperson/copb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244880657,"owners_count":20525515,"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":["composition","currying","functional-programming","overloading","pipes","typescript"],"created_at":"2024-10-14T01:47:01.089Z","updated_at":"2026-05-16T12:32:31.194Z","avatar_url":"https://github.com/jajaperson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# copb [![Version](https://img.shields.io/github/v/tag/jajaperson/copb?label=version)](https://github.com/jajaperson/copb/releases) [![Build Status](https://img.shields.io/github/workflow/status/jajaperson/copb/Test%20Deno%20Module)](https://github.com/jajaperson/copb/actions?query=workflow%3A%22Test+Deno+Module%22)\n\nA functional composition helper for TypesScript that provides type safety\nwithout the need for the usual countless overloads, thanks to some\nfunctional type trickery.\n\nThis module contains just 4 curried functions: [`c`](#c), [`o`](#o), [`p`](#p), [`b`](#b).\n\n## npm install\n\n`copb` is available on [npm](https://npmjs.com/package/copb) as well as \u003chttps://deno.land/x/copb\u003e.\n\n```sh\nnpm install --save copb\n```\n\n## The functions\n\n### `b`\n\n`b` is a simple curried **b**inary composition function, which the other\nfunctions use under the hood.\n\n```ts\nimport { b } from \"https://deno.land/x/copb/mod.ts\";\n\nconst f = (x: number) =\u003e x / 4;\nconst g = (x: number) =\u003e x - 5;\n\n// h = f ∘ g\nconst h = b(f)(g);\n\nconsole.log(h(13)); // -\u003e 2\n```\n\n### `c`\n\n`c` for **c**allable is used to build compositional stacks generated by `o` and\n`p`. Once built, the resultant composed function can be applied in the normal\nway. See usage in the sections below.\n\n### `o`\n\n`o` (named after the mathematical composition symbol) is for more complex\ncompositions, with the ability to compose any number of uniary functions\ntogether.\n\n```ts\nimport { b } from \"https://deno.land/x/copb/mod.ts\";\n\nconst f = (x: string) =\u003e \"number \" + x;\nconst g = (x: number) =\u003e String(x);\nconst h = (x: number) =\u003e x / 3;\nconst l = (x: number) =\u003e x - 6;\n\n// m = f ∘ g ∘ h ∘ l\nconst m = c(o(f)(g)(h)(l));\n\nconsole.log(m(15)); // -\u003e \"number 3\"\n```\n\n### `p`\n\n`p` for **p**ipeline is used to pipe the results of functions to each other. It is\nidentical to `o` except it is read from left to right.\n\n```ts\nimport { b } from \"https://deno.land/x/copb/mod.ts\";\n\nconst f = (x: string) =\u003e \"number \" + x;\nconst g = (x: number) =\u003e String(x);\nconst h = (x: number) =\u003e x / 3;\nconst l = (x: number) =\u003e x - 6;\n\n// m = f ∘ g ∘ h ∘ l\nconst m = c(p(l)(h)(g)(f));\n\nconsole.log(m(15)); // -\u003e \"number 3\"\n```\n\n## Usage notes\n\nApplying a layer of abstraction, you can think of the `o` and `p` functions as\nhaving _nodes_ within the compositional stack. Each of these nodes is denoted in\na seperate set of brackets.\n\n```ts\nc(o(node1)(node2)(node3));\n```\n\nWhen necessary, type annotations can be placed between nodes. For `o`, each\nannotation somewhat counterintuitively represents the input type of the\nfollowing node, and the second annotation of the first node represents the final\nresult.\n\n```ts\nconst m = c(o\u003cstring, string\u003e(f)\u003cnumber\u003e(g)\u003cnumber\u003e(h)\u003cnumber\u003e(l));\n```\n\nFor `p`, each annotation represents the output type of the following node, and\nthe second annotation of the first node represents the final input.\n\n```ts\nconst m = c(p\u003cnumber, number\u003e(l)\u003cnumber\u003e(h)\u003cstring\u003e(g)\u003cstring\u003e(f));\n```\n\n## API\n\nGenerated API documentation, with pseudohaskell illustrations of type\nsignatures, is available\n[here](https://doc.deno.land/https/deno.land/x/copb/mod.ts).\n\n## Comments\n\n### Intellisense\n\nYour IDE will probably show a disgusting, monstrosity of a type signature.\nThat's because this project uses recursive types in order to provide robust type\nsafety. Type checking is still completely functional.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjajaperson%2Fcopb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjajaperson%2Fcopb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjajaperson%2Fcopb/lists"}