{"id":26409746,"url":"https://github.com/metafates/opt","last_synced_at":"2025-03-17T19:36:11.311Z","repository":{"id":279252511,"uuid":"938207174","full_name":"metafates/opt","owner":"metafates","description":"🫥 Yet another option type in Go, but done right","archived":false,"fork":false,"pushed_at":"2025-03-17T09:17:14.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T10:29:18.978Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/metafates/opt","language":"Go","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/metafates.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}},"created_at":"2025-02-24T15:35:26.000Z","updated_at":"2025-03-17T09:17:39.000Z","dependencies_parsed_at":"2025-02-24T16:51:42.001Z","dependency_job_id":null,"html_url":"https://github.com/metafates/opt","commit_stats":null,"previous_names":["metafates/opt"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metafates","download_url":"https://codeload.github.com/metafates/opt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244097682,"owners_count":20397660,"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":[],"created_at":"2025-03-17T19:36:10.645Z","updated_at":"2025-03-17T19:36:11.303Z","avatar_url":"https://github.com/metafates.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Opt\n\n[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/metafates/opt)\n\nOpt is a Go package for safe abstractions over optional values.\n\nInspired by the [Option type in Rust] and follows the same ideas and function signatures.\n\n## Features\n\n- Represent explicitly set values. For example: `{\"b\":2,\"a\":null}` and `{\"b\":2}` would be different states for `a` - explicit and implicit `None`.\n- All the encoding and decoding functionality: json, gob, sql, text \u0026 binary.\n- Adapters to construct options from pointers, zero values, and proto messages.\n- No reflection.\n\n## Install\n\n```bash\ngo get github.com/metafates/opt\n```\n\n## Usage\n\nSee [example_test.go](./example_test.go) for more examples.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/metafates/opt\"\n)\n\ntype User struct {\n\tBirth opt.Opt[time.Time]\n}\n\nfunc (u User) Age() opt.Opt[int] {\n\treturn opt.Map(u.Birth, func(t time.Time) int {\n\t\treturn time.Now().Year() - t.Year()\n\t})\n}\n\nfunc isAdult(age int) bool {\n\treturn age \u003e= 18\n}\n\nfunc getUser(id int) opt.Opt[User] {\n\t// ...\n}\n\nfunc main() {\n\tif opt.AndThen(getUser(42), User.Age).IsSomeAnd(isAdult) {\n\t\tfmt.Println(\"🍺!\")\n\t}\n}\n```\n\n[Option type in Rust]: https://doc.rust-lang.org/std/option/enum.Option.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetafates%2Fopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetafates%2Fopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetafates%2Fopt/lists"}