{"id":18435321,"url":"https://github.com/mnie/resulttype","last_synced_at":"2026-03-11T13:39:10.734Z","repository":{"id":65413851,"uuid":"141833270","full_name":"MNie/ResultType","owner":"MNie","description":"ResultType implementation in C#","archived":false,"fork":false,"pushed_at":"2021-01-05T00:52:27.000Z","size":54,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T19:17:11.074Z","etag":null,"topics":["csharp","functional-programming","result-type"],"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/MNie.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}},"created_at":"2018-07-21T17:33:03.000Z","updated_at":"2024-05-02T21:11:27.000Z","dependencies_parsed_at":"2023-01-22T09:45:17.433Z","dependency_job_id":null,"html_url":"https://github.com/MNie/ResultType","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MNie%2FResultType","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MNie%2FResultType/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MNie%2FResultType/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MNie%2FResultType/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MNie","download_url":"https://codeload.github.com/MNie/ResultType/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991557,"owners_count":21194894,"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":["csharp","functional-programming","result-type"],"created_at":"2024-11-06T06:07:53.864Z","updated_at":"2026-03-11T13:39:10.706Z","avatar_url":"https://github.com/MNie.png","language":"C#","readme":"# ResultType \u0026 ResultType.Validation\n\n* NuGet Status\n\n    |   | ResultType | ResultType.Validation |\n    |---|---|---|\n    | nuget | [![NuGet](https://buildstats.info/nuget/MNie.ResultType?includePreReleases=true)](https://www.nuget.org/packages/MNie.ResultType) | [![NuGet](https://buildstats.info/nuget/MNie.ResultType.Validation?includePreReleases=true)](https://www.nuget.org/packages/MNie.ResultType.Validation) |\n\n\n* Build Status\n    [![Build Status](https://travis-ci.org/MNie/ResultType.svg?branch=master)](https://travis-ci.org/MNie/ResultType)\n\n# ResultType\nResultType implementation in C#\n\nCould be downloaded from NuGet:\n```Install-Package MNie.ResultType```\n\nSimple usage:\n\n* without value\n```csharp\nvar result = ResultFactory.CreateSuccess();\n\nvar error = ResultFactory.CreateFailure\u003cUnit\u003e();\n```\n\n* with value\n```csharp\nvar result = ResultFactory.CreateSuccess(true);\n\nvar error = ResultFactory.CreateFailure\u003cbool\u003e(\"error message\");\n```\n\n* chaining results\n```csharp\nvar result = ResultFactory.CreateSuccess()\n  .Bind(fromPreviousSuccess =\u003e ResultFactory.CreateSuccess(true));\n```\n\n```csharp\nvar result = ResultFactory.CreateSuccess()\n  .Bind(() =\u003e ResultFactory.CreateSuccess(true));\n```\n\n```csharp\nvar result = ResultFactory.CreateSuccess()\n  .Bind((fromPreviousSuccess, fromPreviousFailure) =\u003e ResultFactory.CreateSuccess(true));\n```\n\n* mapping result\n\n```csharp\n[HttpGet]\npublic IActionResult SomeAction() =\u003e\n    \"test\".ToSuccess().Map(Ok, BadRequest);\n```\n\n`Bind` function accepts `Func\u003cTPrevious, TOutput\u003e` or `Func\u003cTOuput\u003e` it depends on you if you want to based on the previous value. There is also an async implementation of `Bind` with `Async` postfix.\nThere are also async functions which in fact are boxing result into a Task.\n```csharp\nResultFactory.CreateSuccessAsync\nResultFactory.CreateFailureAsync\n```\n\n# ResultType.Validation\n\n[ResultType.Validation](https://www.nuget.org/packages/MNie.ResultType.Validation/) package provides a simple Rule class to defines Rules which should apply to some objects and as a result returns ResultType.\nCould be downloaded from NuGet:\n```Install-Package MNie.ResultType.Validation```\n\nexample usage looks like this:\n```csharp\nvar rules = new[]\n{\n    new Rule(() =\u003e \"name\".StartsWith(\"n\"), \"name\"),\n    new Rule(() =\u003e \"dd\".StartsWith(\"e\"), \"dd\"),\n    new Rule(() =\u003e \"hh\".StartsWith(\"a\"), \"hh\"),\n    new Rule(() =\u003e \"hehe\".StartsWith(\"h\"), \"hehe\"),\n};\nvar result = rules.Apply();\n```\n\nBesides `Rule` class package provides also a `RuleBuilder` class. By which you could define predicates based on which Success or Failure would be created.\n\nSample usage:\n```csharp\nclass TestObject\n{\n    public readonly string FieldA;\n    public readonly int FieldB;\n    \n    public TestObject(string fieldA, int fieldB)\n    {\n        FieldA = fieldA;\n        FieldB = fieldB;\n    }\n}\n\n...\n\nvar result = RuleBuilder\n                .Build(() =\u003e new TestObject(\"\", 5))\n                .For(x =\u003e x.FieldB, x =\u003e x \u003e 10, \"greater than 10\")\n                .For(x =\u003e x.FieldB, x =\u003e x \u003c 2, \"less than 2\")\n                .Apply();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnie%2Fresulttype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnie%2Fresulttype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnie%2Fresulttype/lists"}