{"id":18696707,"url":"https://github.com/eminarican/safetypes","last_synced_at":"2025-04-12T07:31:31.060Z","repository":{"id":41568471,"uuid":"471218651","full_name":"eminarican/safetypes","owner":"eminarican","description":"Rust like result and option implementation for golang","archived":false,"fork":false,"pushed_at":"2022-08-30T09:55:16.000Z","size":32,"stargazers_count":33,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-21T06:40:13.421Z","etag":null,"topics":["go","golang","option","option-type","optional","optional-type","result","result-type","rust"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eminarican.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-18T03:04:30.000Z","updated_at":"2024-04-30T12:29:31.000Z","dependencies_parsed_at":"2023-01-16T18:15:50.492Z","dependency_job_id":null,"html_url":"https://github.com/eminarican/safetypes","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eminarican%2Fsafetypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eminarican%2Fsafetypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eminarican%2Fsafetypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eminarican%2Fsafetypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eminarican","download_url":"https://codeload.github.com/eminarican/safetypes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223503132,"owners_count":17156122,"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":["go","golang","option","option-type","optional","optional-type","result","result-type","rust"],"created_at":"2024-11-07T11:20:34.692Z","updated_at":"2024-11-07T11:20:35.318Z","avatar_url":"https://github.com/eminarican.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# safetypes\nRust like result and option implementation for golang\n\njust a reminder, option type is ready for (un)marshalling, mongodb and rethinkdb so feel free to use it with ^^\n\n## Examples\n\n```go\nimport safe \"github.com/eminarican/safetypes\"\n```\n\n### Option\n```go\nfunc checkUnwrap(opt safe.Option[int]) {\n    if opt.IsSome() {\n        println(opt.Unwrap())\n    } else {\n        panic(\"poor option :(\")\n    }\n}\n```\n```go\nfunc checkUnwrapOr(opt safe.Option[int]) {\n    println(opt.UnwrapOr(10))\n}\n```\n```go\nfunc retrunOption(some bool) (opt safe.Option[int]) {\n    if some {\n        return opt.Some(7)\n    }\n    return opt.None()\n}\n```\n```go\ntype Test struct {\n    Field safe.Option[int]\n}\n\nfunc jsonMarshal(t Test) {\n    res := safe.AsResult(json.Marshal(s))\n    if res.IsOk() {\n        // if some: \"Test{Field: 7}\"\n        // if none: \"Test{Field: {}}\"\n        println(res.Unwrap())\n    } else {\n        panic(res.Error())\n    }\n}\n```\n\n### Result\n```go\nfunc checkUnwrap(res safe.Result[int]) {\n    if res.IsOk() {\n        println(res.Unwrap())\n    } else {\n        panic(res.Error())\n    }\n}\n```\n```go\nfunc retrunResult(some bool) (res safe.Result[int]) {\n    if some {\n        return res.Ok(7)\n    }\n    return res.Err(\"some fancy error msg\")\n}\n```\n\n### Note\nError and None methods usable as structless but it doesn't infere types so instead of using `safetypes.None[T]()` and `safetypes.Err[T](\"\")` you could use them as how in examples above\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feminarican%2Fsafetypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feminarican%2Fsafetypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feminarican%2Fsafetypes/lists"}