{"id":17652185,"url":"https://github.com/impworks/matcher","last_synced_at":"2026-07-05T17:31:53.467Z","repository":{"id":144135528,"uuid":"173430951","full_name":"impworks/matcher","owner":"impworks","description":"Pattern matching in C#","archived":false,"fork":false,"pushed_at":"2019-06-03T14:30:24.000Z","size":45,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-25T20:11:08.516Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/impworks.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-03-02T09:53:53.000Z","updated_at":"2019-06-03T14:30:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"40a5b39d-570f-49b0-ba28-557e2b6ed395","html_url":"https://github.com/impworks/matcher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/impworks/matcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fmatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fmatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fmatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fmatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/impworks","download_url":"https://codeload.github.com/impworks/matcher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/impworks%2Fmatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35163846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-05T02:00:06.290Z","response_time":100,"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":[],"created_at":"2024-10-23T11:46:08.057Z","updated_at":"2026-07-05T17:31:53.460Z","avatar_url":"https://github.com/impworks.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Matcher\n\n![AppVeyor](https://img.shields.io/appveyor/ci/impworks/Matcher.svg) ![AppVeyor Tests](https://img.shields.io/appveyor/tests/impworks/Matcher.svg) [![NuGet](https://img.shields.io/nuget/v/Impworks.Matcher.svg)](https://www.nuget.org/packages/Impworks.Matcher/) ![NuGet Downloads](https://img.shields.io/nuget/dt/Impworks.Matcher.svg)\n\nA proof-of-concept library for strongly-typed pattern matching in C#.\n\n### Basic syntax\n\n```csharp\nvar result = Match.Value(3)\n                  .AndReturn\u003cstring\u003e()\n                  .With(ctx =\u003e\n                  {\n                      ctx.Value(1, \"one\");\n                      ctx.Value(2, \"two\");\n                      ctx.Value(3, \"three\");\n                      ctx.Default(x =\u003e $\"just {x}\");\n                  });\n```\n\n### Supported stuff\n\nArray destructuring (up to 10 elements):\n\n```csharp\nMatch.Value(new [] { 1, 2, 3 })\n     .AndReturn\u003cstring\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.Array(() =\u003e \"empty array\");\n         ctx.Array(a =\u003e $\"just {a}\");\n         ctx.Array((a, b) =\u003e $\"{a} and {b}\");\n         ctx.Array((a, b, c) =\u003e $\"{a}, {b}, and {c}\");\n         ctx.Default(x =\u003e $\"array with {x.Length} values\");\n     });\n```\n\nArray with a last argument as \"rest\":\n\n```csharp\nMatch.Value(new [] { 1, 2, 3 })\n     .AndReturn\u003cstring\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.ArrayRest((a, rest) =\u003e $\"{a} and {rest.Length} more\"); // 1 and 2 more\n     });\n```\n\nSequences (`IEnumerable\u003cT\u003e`) are also supported similar to arrays with the `Seq` and `SeqRest` methods.\n\nTuple deconstructing (supports `ValueTuple` as well):\n\n```csharp\nMatch.Value(Tuple.Create(1, 2, 3))\n     .AndReturn\u003cstring\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.Tuple((a, b, c) =\u003e a + b + c); // equals 6\n     });\n```\n\nNullable value unpacking:\n\n```csharp\nMatch.Value((int?)10)\n     .AndReturn\u003cstring\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.Option(i =\u003e $\"Value is {i}\"); // value is 10\n     });\n```\n\nType checking:\n\n```csharp\nMatch.Value(new Child())\n     .AndReturn\u003cbool\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.OfType().Is\u003cChild\u003e(x =\u003e true);         // true\n         ctx.OfType().Is\u003cParent\u003e(x =\u003e true);        // true\n         ctx.OfType().IsExactly\u003cChild\u003e(x =\u003e true);  // true\n         ctx.OfType().IsExactly\u003cParent\u003e(x =\u003e true); // false\n     });\n```\n\nArbitrary nested patterns:\n\n```csharp\nMatch.Value(Tuple.Create(1, true, new[] { 1, 2, 3 }))\n     .AndReturn\u003cstring\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.Pattern(p =\u003e\n                p.Tuple(\n                    1,\n                    p.Var(\"b\").OfType\u003cbool\u003e(),\n                    p.Array(\n                        1,\n                        p.Var(\"a\"),\n                        p.Any()\n                    )\n                )\n            )\n            .Map\u003cint, bool\u003e((a, b) =\u003e $\"{a} and {b}\"); // 2 and True\n     });\n```\n\nRegex matches:\n\n```csharp\nMatch.Value(\"code is 123\")\n     .AndReturn\u003cint\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.Regex(\"[0-9]+\", v =\u003e int.Parse(v)); // 123\n     });\n```\n\nWhen guards (similarly supported for all other constructs):\n\n```csharp\nMatch.Value(new [] { 1, 2, 3 })\n     .AndReturn\u003cstring\u003e()\n     .With(ctx =\u003e\n     {\n         ctx.Array((a, b, c) =\u003e Option.When(a \u003e b \u0026\u0026 b \u003e c, \"decreasing\"));\n         ctx.Array((a, b, c) =\u003e Option.When(c \u003e b \u0026\u0026 b \u003e a, \"increasing\")); // this\n     });\n```\n\n### Known limitations\n\n* Arbitrary patterns do not allow static type checking and require explicit type annotations.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimpworks%2Fmatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimpworks%2Fmatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimpworks%2Fmatcher/lists"}