{"id":13735370,"url":"https://github.com/arnetheduck/nim-results","last_synced_at":"2025-04-06T21:14:47.484Z","repository":{"id":33269402,"uuid":"134117469","full_name":"arnetheduck/nim-results","owner":"arnetheduck","description":"Friendly value-or-error type","archived":false,"fork":false,"pushed_at":"2025-01-13T11:11:58.000Z","size":142,"stargazers_count":159,"open_issues_count":9,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T20:11:10.387Z","etag":null,"topics":["error-handling","nim","result"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arnetheduck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHEv2","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}},"created_at":"2018-05-20T03:44:24.000Z","updated_at":"2025-03-11T16:04:41.000Z","dependencies_parsed_at":"2024-08-22T08:53:41.093Z","dependency_job_id":"90796b37-b336-4489-84f7-7a4ae3f63406","html_url":"https://github.com/arnetheduck/nim-results","commit_stats":null,"previous_names":["arnetheduck/nim-result"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnetheduck%2Fnim-results","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnetheduck%2Fnim-results/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnetheduck%2Fnim-results/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnetheduck%2Fnim-results/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnetheduck","download_url":"https://codeload.github.com/arnetheduck/nim-results/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550689,"owners_count":20956987,"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":["error-handling","nim","result"],"created_at":"2024-08-03T03:01:06.150Z","updated_at":"2025-04-06T21:14:47.461Z","avatar_url":"https://github.com/arnetheduck.png","language":"Nim","funding_links":[],"categories":["Language Features"],"sub_categories":["Error Handling"],"readme":"# Introduction\n\nResult type that can hold either a value or an error, but not both\n\n## Usage\n\nAdd the following to your `.nimble` file:\n\n```\nrequires \"results\"\n```\n\nor just drop the file in your project!\n\n## Example\n\n```nim\nimport results\n\n# Re-export `results` so that API is always available to users of your module!\nexport results\n\n# It's convenient to create an alias - most likely, you'll do just fine\n# with strings or cstrings as error for a start\n\ntype R = Result[int, string]\n\n# Once you have a type, use `ok` and `err`:\n\nfunc works(): R =\n  # ok says it went... ok!\n  R.ok 42\nfunc fails(): R =\n  # or type it like this, to not repeat the type:\n  result.err \"bad luck\"\n\nfunc alsoWorks(): R =\n  # or just use the shortcut - auto-deduced from the return type!\n  ok(24)\n\nif (let w = works(); w.isOk):\n  echo w[], \" or use value: \", w.value\n\n# In case you think your callers want to differentiate between errors:\ntype\n  Error = enum\n    a, b, c\n  type RE[T] = Result[T, Error]\n\n# You can use the question mark operator to pass errors up the call stack\nfunc f(): R =\n  let x = ?works() - ?fails()\n  assert false, \"will never reach\"\n\n# If you provide this exception converter, this exception will be raised on\n# `tryGet`:\nfunc toException(v: Error): ref CatchableError = (ref CatchableError)(msg: $v)\ntry:\n  RE[int].err(a).tryGet()\nexcept CatchableError:\n  echo \"in here!\"\n\n# You can use `Opt[T]` as a replacement for `Option` = `Opt` is an alias for\n# `Result[T, void]`, meaning you can use the full `Result` API on it:\nlet x = Opt[int].ok(42)\necho x.get()\n\n# ... or `Result[void, E]` as a replacement for `bool`, providing extra error\n# information!\nlet y = Result[void, string].err(\"computation failed\")\necho y.error()\n\n\n```\n\nSee [results.nim](./results.nim) for more in-depth documentation - specially\ntowards the end where there are plenty of examples!\n\n## License\n\nMIT license, just like Nim, or Apache, if you prefer that\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnetheduck%2Fnim-results","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnetheduck%2Fnim-results","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnetheduck%2Fnim-results/lists"}