{"id":51495857,"url":"https://github.com/nuskey8/valueresult","last_synced_at":"2026-07-07T15:01:47.244Z","repository":{"id":357403009,"uuid":"1236578452","full_name":"nuskey8/ValueResult","owner":"nuskey8","description":"A lightweight, zero-allocation result type implementation for C#.","archived":false,"fork":false,"pushed_at":"2026-05-13T07:21:54.000Z","size":14,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-06T13:58:58.274Z","etag":null,"topics":["csharp","dotnet","result-type"],"latest_commit_sha":null,"homepage":"","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/nuskey8.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":"2026-05-12T11:31:27.000Z","updated_at":"2026-06-29T01:50:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/nuskey8/ValueResult","commit_stats":null,"previous_names":["nuskey8/valueresult"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nuskey8/ValueResult","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FValueResult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FValueResult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FValueResult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FValueResult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuskey8","download_url":"https://codeload.github.com/nuskey8/ValueResult/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FValueResult/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35232326,"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-07T02:00:07.222Z","response_time":90,"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":["csharp","dotnet","result-type"],"created_at":"2026-07-07T15:01:45.083Z","updated_at":"2026-07-07T15:01:47.185Z","avatar_url":"https://github.com/nuskey8.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ValueResult\n\n[![Nuget](https://img.shields.io/nuget/v/valueresult.svg)](https://www.nuget.org/packages/ValueResult/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\nA lightweight, zero-allocation result type implementation for C#. \n\n`ValueResult\u003cT, E\u003e` is a discriminated union that represents either a successful value (`Ok`) or an error value (`Error`), enabling functional error handling without exceptions.\n\n## Features\n\n- **Zero-allocation struct**: Implemented as a `readonly struct` for maximum performance\n- **Functional API**: `Select`, `AndThen`, `OrElse`, `Match` operations for composable error handling\n- **Exception handling**: Built-in `Try\u003cT\u003e` helper to convert exceptions to results\n\n## Installation\n\n```bash\ndotnet add package ValueResult\n```\n\n## Quick Start\n\n### Creating Results\n\n```csharp\n// Create an Ok result with implicit conversion\nValueResult\u003cint, string\u003e okResult = 42;\n\n// Create an Error result with implicit conversion\nValueResult\u003cint, string\u003e errorResult = \"Something went wrong\";\n\n// Using helper methods\nvar success = ValueResult.Ok\u003cint, string\u003e(100);\nvar failure = ValueResult.Error\u003cint, string\u003e(\"Error message\");\n```\n\n### Checking Results\n\n```csharp\nvar result = ValueResult.Ok\u003cint, string\u003e(42);\n\nif (result.IsOk)\n{\n    int value = result.GetValue();\n    Console.WriteLine($\"Success: {value}\");\n}\n\nif (result.IsError)\n{\n    string error = result.GetError();\n    Console.WriteLine($\"Error: {error}\");\n}\n```\n\n### Extracting Values\n\n```csharp\nvar result = ValueResult.Ok\u003cint, string\u003e(42);\n\nint value = result.GetValue();\nint valueOrDefault = result.GetValueOr(0);\nint maybeValue = result.GetValueOrDefault();\nint unsafeValue = result.UnsafeGetValue();\n```\n\n### Exception Handling\n\nConvert exceptions to results with the `Try\u003cT\u003e` helper:\n\n```csharp\nvar result = ValueResult.Try(() =\u003e int.Parse(\"not-a-number\"));\n\nif (result.IsError)\n{\n    Exception ex = result.GetError();\n    Console.WriteLine($\"Parsing failed: {ex.Message}\");\n}\n```\n\n## Operators\n\n### Select\n\n```csharp\nvar result = ValueResult.Ok\u003cint, string\u003e(10);\n\nvar doubled = result.Select(x =\u003e x * 2);\n// doubled is Ok\u003cint, string\u003e(20)\n\nvar asString = result.Select(x =\u003e $\"Value: {x}\");\n// asString is Ok\u003cstring, string\u003e(\"Value: 10\")\n```\n\n### SelectError\n\n```csharp\nvar result = ValueResult.Error\u003cint, string\u003e(\"error\");\n\nvar httpStatus = result.SelectError(err =\u003e 500);\n// httpStatus is Error\u003cint, int\u003e(500)\n```\n\n### AndThen\n\n```csharp\nValueResult\u003cint, string\u003e ParseInt(string input)\n{\n    if (int.TryParse(input, out var value))\n        return value;\n    return \"Invalid integer\";\n}\n\nValueResult\u003cint, string\u003e Divide(int a, int b)\n{\n    if (b == 0)\n        return \"Division by zero\";\n    return a / b;\n}\n\nvar result = ParseInt(\"10\")\n    .AndThen(x =\u003e Divide(x, 2));\n// Success: 5\n```\n\n### OrElse\n\n```csharp\nvar result = ValueResult.Error\u003cint, string\u003e(\"First error\")\n    .OrElse(err =\u003e \n    {\n        if (err == \"First error\")\n            return 42; // Recover with fallback value\n        return err; // Propagate other errors\n    });\n// Success: 42\n```\n\n### And\n\n```csharp\nvar result1 = ValueResult.Ok\u003cint, string\u003e(10);\nvar result2 = ValueResult.Ok\u003cint, string\u003e(20);\n\nvar combined = result1.And(result2);\n// combined is result2 (since result1 is Ok)\n```\n\n### Or\n\n```csharp\nvar result1 = ValueResult.Error\u003cint, string\u003e(\"Failed\");\nvar result2 = ValueResult.Ok\u003cint, string\u003e(42);\n\nvar fallback = result1.Or(result2);\n// fallback is Ok\u003cint, string\u003e(42)\n```\n\n### Match\n\n```csharp\nvar result = ValueResult.Ok\u003cint, string\u003e(42);\n\nresult.Match(\n    value =\u003e Console.WriteLine($\"Success: {value}\"),\n    error =\u003e Console.WriteLine($\"Error: {error}\")\n);\n\n// C# 15 union also supported\n_ = result switch\n{\n    int value =\u003e $\"Success: {value}\",\n    string error =\u003e $\"Error: {error}\",\n};\n```\n\n## License\n\nThis library is provided under the [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuskey8%2Fvalueresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuskey8%2Fvalueresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuskey8%2Fvalueresult/lists"}