{"id":18053786,"url":"https://github.com/hymkor/go-minimal-optional","last_synced_at":"2025-04-05T08:21:42.174Z","repository":{"id":160998930,"uuid":"627719505","full_name":"hymkor/go-minimal-optional","owner":"hymkor","description":"The minimal `optional` package for golang","archived":false,"fork":false,"pushed_at":"2024-03-10T01:15:08.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T15:50:55.712Z","etag":null,"topics":["generics","go","golang","optional"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/hymkor/go-minimal-optional","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/hymkor.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":"2023-04-14T03:49:44.000Z","updated_at":"2024-03-09T07:33:24.000Z","dependencies_parsed_at":"2024-03-09T06:33:00.235Z","dependency_job_id":"9c17e1d9-f997-40f7-a9d3-76e1eb09c3e4","html_url":"https://github.com/hymkor/go-minimal-optional","commit_stats":null,"previous_names":["hymkor/go-minimum-optional"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-minimal-optional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-minimal-optional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-minimal-optional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-minimal-optional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hymkor","download_url":"https://codeload.github.com/hymkor/go-minimal-optional/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247307328,"owners_count":20917448,"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":["generics","go","golang","optional"],"created_at":"2024-10-31T00:08:03.260Z","updated_at":"2025-04-05T08:21:42.147Z","avatar_url":"https://github.com/hymkor.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/hymkor/go-minimal-optional.svg)](https://pkg.go.dev/github.com/hymkor/go-minimal-optional)\r\n\r\ngo-minimal-optional\r\n===================\r\n\r\nThis package has only two constructors (Some, None) and three methods (IfSome, IsNone, Match).\r\n\r\n+ `optional.Value` is an array whose size is 0 or 1. Therefore, the contents can be handled with for-range even in versions below Go 1.22.\r\n+ `optional.Option` was renamed to `optional.Value`\r\n\r\n```example.go\r\npackage main\r\n\r\nimport (\r\n    \"github.com/hymkor/go-minimal-optional\"\r\n)\r\n\r\nfunc test(x optional.Value[int]) {\r\n    x.IfSome(func(v int) {\r\n        println(\"   IfSome: it has a value:\", v)\r\n    })\r\n\r\n    for _, v := range x {\r\n        println(\"   for-range(ready for v1.18): it has a value:\", v)\r\n    }\r\n\r\n    // GOEXPRIMENT=rangefunc is required to build following line.\r\n    for v := range x.Each {\r\n        println(\"   for-range(v1.22 X:rangefunc): it has a value:\", v)\r\n    }\r\n\r\n    if x.IsNone() {\r\n        println(\"   IsNone: it does not have a value\")\r\n    }\r\n\r\n    x.Match(func(v int) {\r\n        println(\"   Match: it has a value:\", v)\r\n    }, func() {\r\n        println(\"   Match: it does not hava a value\")\r\n    })\r\n\r\n    println()\r\n}\r\n\r\nfunc main() {\r\n    println(\"None[int]\")\r\n    test(optional.None[int]())\r\n\r\n    println(\"Some(4)\")\r\n    test(optional.Some(4))\r\n}\r\n```\r\n\r\n**env GOEXPERIMENT=rangefunc go run example.go**\r\n\r\n```env GOEXPERIMENT=rangefunc go run example.go|\r\nNone[int]\r\n   IsNone: it does not have a value\r\n   Match: it does not hava a value\r\n\r\nSome(4)\r\n   IfSome: it has a value: 4\r\n   for-range(ready for v1.18): it has a value: 4\r\n   for-range(v1.22 X:rangefunc): it has a value: 4\r\n   Match: it has a value: 4\r\n\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhymkor%2Fgo-minimal-optional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhymkor%2Fgo-minimal-optional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhymkor%2Fgo-minimal-optional/lists"}