{"id":17228295,"url":"https://github.com/hojberg/sums-up","last_synced_at":"2026-03-04T03:01:32.626Z","repository":{"id":42918758,"uuid":"147255149","full_name":"hojberg/sums-up","owner":"hojberg","description":"SumTypes in TypeScript","archived":false,"fork":false,"pushed_at":"2023-01-05T10:13:59.000Z","size":974,"stargazers_count":30,"open_issues_count":10,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T01:35:57.452Z","etag":null,"topics":["adt","fp","functional-programming","javascript","typescript"],"latest_commit_sha":null,"homepage":null,"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/hojberg.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-09-03T21:26:37.000Z","updated_at":"2024-08-09T06:09:59.000Z","dependencies_parsed_at":"2023-02-04T00:16:55.353Z","dependency_job_id":null,"html_url":"https://github.com/hojberg/sums-up","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/hojberg/sums-up","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hojberg%2Fsums-up","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hojberg%2Fsums-up/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hojberg%2Fsums-up/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hojberg%2Fsums-up/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hojberg","download_url":"https://codeload.github.com/hojberg/sums-up/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hojberg%2Fsums-up/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30070479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T01:03:42.280Z","status":"online","status_checked_at":"2026-03-04T02:00:07.464Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["adt","fp","functional-programming","javascript","typescript"],"created_at":"2024-10-15T04:43:16.645Z","updated_at":"2026-03-04T03:01:32.610Z","avatar_url":"https://github.com/hojberg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"👍 Sums Up\n===\n\n### Installation\n\n```\nnpm install sums-up\n```\n\n### Example\n\nIn TypeScript:\n\n```typescript\nimport SumType from 'sums-up';\n\nclass Maybe\u003cT\u003e extends SumType\u003c{ Just: [T]; Nothing: [] }\u003e {}\n\nfunction Just\u003cT\u003e(value: T): Maybe\u003cT\u003e {\n  return new Maybe(\"Just\", value);\n}\n\nfunction Nothing\u003cT\u003e(): Maybe\u003cT\u003e {\n  return new Maybe(\"Nothing\");\n}\n\nconst x = Just(\"foo\");\n\nconst result = x.caseOf({\n  Nothing: () =\u003e \"nope\",\n  Just: (a) =\u003e a + \"bar\",\n});\n```\n\nOr in JavaScript\n\n```javascript\nimport SumType from 'sums-up';\n\nclass Maybe extends SumType {}\n\nfunction Just(value) {\n  return new Maybe(\"Just\", value);\n}\n\nfunction Nothing() {\n  return new Maybe(\"Nothing\");\n}\n\nconst x = Just(\"foo\");\n\nconst result = x.caseOf({\n  Nothing: () =\u003e \"nope\",\n  Just: (a) =\u003e a + \"bar\",\n});\n```\n\n### Wildcard Matching\n\nIf the kind of a sum type instance isn't present in the pattern given to `caseOf`, a default key called `_` will be used instead.\n\n```ts\nimport SumType from 'sums-up';\n\nclass RequestState\u003cT = never\u003e extends SumType\u003c{\n  NotStarted: [];\n  Connecting: [];\n  Downloading: [number];\n  Completed: [T];\n  Failed: [string];\n}\u003e {}\n\nconst state = new RequestState('Failed', 'Connection reset.');\nconst progressPercentage = state.caseOf({\n  Downloading: pct =\u003e pct,\n  Completed: () =\u003e 100,\n  _: () =\u003e 0\n});\n```\n\nContributors: \n\n@hojberg @dfreeman @AdamEdgett\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhojberg%2Fsums-up","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhojberg%2Fsums-up","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhojberg%2Fsums-up/lists"}