{"id":13496256,"url":"https://github.com/algebraic-graphs/typescript","last_synced_at":"2025-03-28T18:31:46.560Z","repository":{"id":41388041,"uuid":"237417422","full_name":"algebraic-graphs/typescript","owner":"algebraic-graphs","description":"Algebraic graphs implementation in TypeScript","archived":false,"fork":false,"pushed_at":"2023-03-03T12:35:30.000Z","size":338,"stargazers_count":132,"open_issues_count":5,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-21T15:18:53.635Z","etag":null,"topics":["algebra","algebraic","fp","fp-ts","graph","graphs"],"latest_commit_sha":null,"homepage":null,"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/algebraic-graphs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-01-31T11:33:29.000Z","updated_at":"2025-03-15T00:56:17.000Z","dependencies_parsed_at":"2024-01-16T09:54:13.449Z","dependency_job_id":"7ab08f0e-2a33-4d60-a936-f802e6bb4f6e","html_url":"https://github.com/algebraic-graphs/typescript","commit_stats":null,"previous_names":["ybogomolov/alga-ts"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algebraic-graphs%2Ftypescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algebraic-graphs%2Ftypescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algebraic-graphs%2Ftypescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algebraic-graphs%2Ftypescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algebraic-graphs","download_url":"https://codeload.github.com/algebraic-graphs/typescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246080634,"owners_count":20720562,"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":["algebra","algebraic","fp","fp-ts","graph","graphs"],"created_at":"2024-07-31T19:01:44.644Z","updated_at":"2025-03-28T18:31:46.139Z","avatar_url":"https://github.com/algebraic-graphs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Algebraic graphs implementation in TypeScript\n\n[![npm](https://img.shields.io/npm/v/alga-ts.svg)](https://www.npmjs.com/package/alga-ts)\n[![Build Status](https://travis-ci.org/algebraic-graphs/typescript.svg)](https://travis-ci.org/algebraic-graphs/typescript)\n\n\n`alga-ts` is a library for algebraic construction and manipulation of graphs in TypeScript. This is a TypeScript port of [alga](https://github.com/snowleopard/alga) and [alga-scala](https://github.com/algebraic-graphs/scala).\n\n\u003e See [this Haskell Symposium paper](https://github.com/snowleopard/alga-paper) and the corresponding [talk](https://www.youtube.com/watch?v=EdQGLewU-8k) for the motivation behind the library, the underlying theory and implementation details. There is also a [Haskell eXchange talk](https://skillsmatter.com/skillscasts/10635-algebraic-graphs), and a [tutorial](https://nobrakal.github.io/alga-tutorial) by Alexandre Moine.\n\n**N.B.** Please note that this project is WIP, so use it at your own discretion.\n\n## Installation\n\nThe main library, `alga-ts`, is available at the NPM. As it uses [fp-ts](https://github.com/gcanti/fp-ts) for higher-kinded types, be sure to install it as well:\n\n```sh\nnpm install --save alga-ts fp-ts\n```\n\n## Usage\n\nTo begin using `alga-ts`, you first need to obtain an instance of it's API for the given [Eq](https://dev.to/gcanti/getting-started-with-fp-ts-setoid-39f3) of your target data type. Consider the example:\n\n```ts\nimport { getStructEq, eqNumber, eqString } from 'fp-ts/lib/Eq';\nimport { getInstanceFor } from 'alga-ts';\n\ninterface User {\n  name: string;\n  age: number;\n}\n\nconst eqUser = getStructEq({\n  name: eqString,\n  age: eqNumber,\n});\n\nconst G = getInstanceFor(eqUser);\n```\n\nNow `G` is a module containing all methods \u0026 constructors required to work with graphs of `User`:\n\n```ts\nconst user1: User = { name: 'Alice', age: 32 };\nconst user2: User = { name: 'Bob', age: 41 };\nconst user3: User = { name: 'Charlie', age: 28 };\n\nconst graph1 = G.connect(\n  G.edge(user1, user2),\n  G.edge(user2, user3),\n);\n\nconsole.log(G.hasEdge(user1, user3, graph1)); // =\u003e true\n```\n\n### Pipeable graphs\n\nAlgbraic graphs happen to have type class instances for `Monad` (and, consequently, for `Functor` and `Applicative`) and `Alternative`. API instance, obtained via `getInstanceFor`, exposes methods from these type classes in a data-last form, so they could be used with `pipe` from `fp-ts`:\n\n```ts\nimport { pipe } from 'fp-ts/lib/pipeable';\nimport { getInstanceFor } from 'alga-ts';\n\nconst GS = getInstanceFor(eqString);\n\n...\n\nconst graph2 = pipe(\n  graph1,\n  G.map(u =\u003e u.name),\n);\n\nconsole.log(GS.hasEdge('Alice', 'Charlie', graph2)); // =\u003e true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgebraic-graphs%2Ftypescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgebraic-graphs%2Ftypescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgebraic-graphs%2Ftypescript/lists"}