{"id":18053771,"url":"https://github.com/hymkor/go-tiny-optional","last_synced_at":"2025-04-05T08:21:35.308Z","repository":{"id":226715579,"uuid":"769470945","full_name":"hymkor/go-tiny-optional","owner":"hymkor","description":"The tiny `optional` package for golang ","archived":false,"fork":false,"pushed_at":"2024-03-10T00:56:00.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T15:50:55.352Z","etag":null,"topics":["go","golang","optional"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/hymkor/go-tiny-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":"2024-03-09T06:57:08.000Z","updated_at":"2024-03-09T13:57:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"8aae7177-5a08-4fee-9b70-c917c0c3e88c","html_url":"https://github.com/hymkor/go-tiny-optional","commit_stats":null,"previous_names":["hymkor/go-tiny-optional"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-tiny-optional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-tiny-optional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-tiny-optional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-tiny-optional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hymkor","download_url":"https://codeload.github.com/hymkor/go-tiny-optional/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247307327,"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":["go","golang","optional"],"created_at":"2024-10-31T00:08:00.765Z","updated_at":"2025-04-05T08:21:35.264Z","avatar_url":"https://github.com/hymkor.png","language":"Go","readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/hymkor/go-tiny-optional.svg)](https://pkg.go.dev/github.com/hymkor/go-tiny-optional)\r\n\r\ngo-tiny-optional\r\n===================\r\n\r\nThis package has only two constructors (Some, None) and four methods (IfSome, IsNone, Each, Match).\r\n\r\n```example.go\r\npackage main\r\n\r\nimport (\r\n    \"github.com/hymkor/go-tiny-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    // 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(v1.22 X:rangefunc): it has a value: 4\r\n   Match: it has a value: 4\r\n\r\n```\r\n\r\nComparison with [go-minimal-optional]\r\n-------------------------------------\r\n\r\n### Type\r\n\r\n#### go-minimal-optional\r\n\r\n```\r\ntype Value[T any] []T\r\n```\r\n\r\n#### go-tiny-optional\r\n\r\n```\r\ntype Value[T any] struct {\r\n    value T\r\n    ok    bool\r\n}\r\n```\r\n\r\n### Speed\r\n\r\n#### go-minimal-optional\r\n\r\n```\r\n$ go test -bench . -benchmem\r\ngoos: windows\r\ngoarch: amd64\r\npkg: github.com/hymkor/go-minimal-optional\r\ncpu: Intel(R) Core(TM) i5-6500T CPU @ 2.50GHz\r\nBenchmarkIfSome-4       656701584                1.790 ns/op           0 B/op          0 allocs/op\r\nBenchmarkIfNone-4       1000000000               0.7019 ns/op          0 B/op          0 allocs/op\r\nPASS\r\nok      github.com/hymkor/go-minimal-optional   2.315s\r\n```\r\n\r\n#### go-tiny-optional\r\n\r\n```\r\n$ go test -bench . -benchmem\r\ngoos: windows\r\ngoarch: amd64\r\npkg: github.com/hymkor/go-tiny-optional\r\ncpu: Intel(R) Core(TM) i5-6500T CPU @ 2.50GHz\r\nBenchmarkIfSome-4       675800485                1.787 ns/op           0 B/op          0 allocs/op\r\nBenchmarkIfNone-4       1000000000               0.7008 ns/op          0 B/op          0 allocs/op\r\nPASS\r\nok      github.com/hymkor/go-tiny-optional      2.325s\r\n```\r\n\r\n[go-minimal-optional]: https://github.com/hymkor/go-minimal-optional\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhymkor%2Fgo-tiny-optional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhymkor%2Fgo-tiny-optional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhymkor%2Fgo-tiny-optional/lists"}