{"id":19961147,"url":"https://github.com/fisothemes/result-cpp","last_synced_at":"2025-03-01T16:25:47.756Z","repository":{"id":214440415,"uuid":"736147355","full_name":"fisothemes/Result-CPP","owner":"fisothemes","description":"A lightweight, header-only C++ library that provides a result type for monadic error handling .","archived":false,"fork":false,"pushed_at":"2024-01-05T04:43:59.000Z","size":213,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T07:43:54.098Z","etag":null,"topics":["cpp","cpp17","error","error-handling","expected","expected-value","header-only","result"],"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/fisothemes.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":"2023-12-27T05:42:11.000Z","updated_at":"2023-12-28T07:09:53.000Z","dependencies_parsed_at":"2023-12-28T08:26:40.593Z","dependency_job_id":"2fe8320f-eda7-4870-9eb0-e70fd4687245","html_url":"https://github.com/fisothemes/Result-CPP","commit_stats":null,"previous_names":["fisothemes/result-cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fisothemes%2FResult-CPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fisothemes%2FResult-CPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fisothemes%2FResult-CPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fisothemes%2FResult-CPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fisothemes","download_url":"https://codeload.github.com/fisothemes/Result-CPP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241391562,"owners_count":19955550,"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":["cpp","cpp17","error","error-handling","expected","expected-value","header-only","result"],"created_at":"2024-11-13T02:06:31.771Z","updated_at":"2025-03-01T16:25:47.731Z","avatar_url":"https://github.com/fisothemes.png","language":"C++","readme":"# Result-CPP\n\nResult-CPP is a lightweight, header-only C++ library for error handling using the monadic pattern in C++. It provides a generic class called `result` that can store either a successful value or an error value as well as ways to extract and handle them.\n\n## Features\n\n- Simple and concise result type for error handling.\n- Header-only library with no external dependencies.\n- Supports chaining operations and handling errors.\n\n## Getting Started\n\n### Prerequisites\n\n- C++17 compiler\n\n### Usage\n\n1. Include the `result.hpp` header in your C++ project.\n2. Start using the `fst::result` type for handling success and error states.\n\n### Example\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003climits\u003e\n\n#include \"fst/result.hpp\"\n\n// Function that may fail and return a Result\nfst::result\u003cdouble, std::string\u003e div(double a, double b) {\n  if (b == 0.0)\n    return std::string(\"Division by zero error\");  // Implicitly converts to std::string\n  return a / b;  // Implicitly converts to double\n}\n\nint main() {\n// Example 1: Chaining with `and_then` and `map`\nauto result1 = div(12.0, 3.0)\n                    .and_then([](const auto\u0026 x) {\n                      return x \u003e 0.0 \n                          ? fst::result\u003cdouble, std::string\u003e(x * 2.0) \n                          : fst::result\u003cdouble, std::string\u003e(\"Negative result\");\n                    })\n                    .map([](const auto\u0026 y) {\n                      std::cout \u003c\u003c \"Result: \" + std::to_string(y) \u003c\u003c '\\n';\n                      return y*y;\n                    });\n\nstd::cout \u003c\u003c \"Example 1: \" \u003c\u003c result1 \u003c\u003c '\\n';\n\n// Example 2: Chaining with `or_else` and `map_error`\nauto result2 = div(10.0, 0.0)\n                    .or_else([](const auto\u0026 error) {\n                      return fst::result\u003cdouble, std::string\u003e(\"Error: \" + error);\n                    })\n                    .map_error([](const std::string\u0026 original_error) {\n                      return original_error + \" (mapped)\";\n                    });\n\nstd::cout \u003c\u003c \"Example 2: \" \u003c\u003c result2 \u003c\u003c '\\n';\n\n// Example 3: Chaining with `transform`\nauto result3 = div(20.0, 4.0)\n                    .transform([](const auto\u0026 res) {\n                      return res.success() \n                          ? fst::result\u003cstd::string, std::string\u003e(\n                                fst::success_t, \n                                \"Success! No error\") \n                          : fst::result\u003cstd::string, std::string\u003e(\n                                fst::error_t,\n                                res.error()\n                                   .value_or(\"Unknown error\"));\n                    });\n\nstd::cout \u003c\u003c \"Example 3: \" \u003c\u003c result3 \u003c\u003c '\\n';\n\n// Example 4: Using `inspect` for side effects\nauto result4 = div(8.0, 2.0)\n                   .inspect([](const fst::result\u003cdouble, std::string\u003e\u0026 res) {\n                     if (auto value = res.success()) {\n                       std::cout \u003c\u003c \"Success! Result is: \" \n                                 \u003c\u003c *value \n                                 \u003c\u003c '\\n';\n                     } else {\n                       std::cerr \u003c\u003c \"Error! Message: \" \n                                 \u003c\u003c res.error()\n                                       .value_or(\"Unknown error\") \n                                 \u003c\u003c '\\n';\n                     }\n                   });\n\n std::cout \u003c\u003c \"Example 4: \" \u003c\u003c result4 \u003c\u003c '\\n';\n\n  return 0;\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffisothemes%2Fresult-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffisothemes%2Fresult-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffisothemes%2Fresult-cpp/lists"}