{"id":17043439,"url":"https://github.com/leavez/go-optional","last_synced_at":"2026-05-18T03:08:27.548Z","repository":{"id":57662709,"uuid":"478533769","full_name":"leavez/go-optional","owner":"leavez","description":"optional type for golang","archived":false,"fork":false,"pushed_at":"2022-04-13T12:12:58.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-17T06:50:23.493Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/leavez.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}},"created_at":"2022-04-06T11:41:23.000Z","updated_at":"2025-03-29T12:10:37.000Z","dependencies_parsed_at":"2022-09-13T07:00:49.085Z","dependency_job_id":null,"html_url":"https://github.com/leavez/go-optional","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/leavez/go-optional","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Fgo-optional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Fgo-optional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Fgo-optional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Fgo-optional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leavez","download_url":"https://codeload.github.com/leavez/go-optional/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Fgo-optional/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2024-10-14T09:29:32.478Z","updated_at":"2026-05-18T03:08:27.531Z","avatar_url":"https://github.com/leavez.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-optional\n\nThe `optional` type for golang, implemented with generics (go 1.18).\n\n## TLDR\n```golang\nvar v optional.Type[int] = optional.New(123)\nif unwrapped, ok := v.Value(); ok {\n    unwrapped // 123\n}\n\nv.IsNil()      // false\nv.ForceValue() // 123\n```\n\n## Methods\n\n### initializer\n- `optional.New(XX)` \n\nIf XX is nil, it returns Nil\n\n- `optional.Nil()`\n- (`optional.FromPtr(XXX)` returns optional.Nil() if pointer is nil) \n\n### value\n- `Value()`\n```golang\nvar v = optional.New(123)\nif unwrapped, ok := v.Value(); ok {\n    unwrapped // 123\n}\n```\n- `ForceValue()`\n- `IsNil()`\n\n\n- `ValueOrDefault(XX)`\n- `ValueOrLazyDefault(f)`\n\n### transform\n\n- Map\n\n```golang\noptional.Map( optional.New(123), func(t int) string {\n    return fmt.Sprintf(\"hello %d\", t)\n}) // optional.Type[string]\n```\n\n- Compact\n\n```golang\nvar v = optional.New(optional.New(123))\noptional.Compact(v) // optional.Type[int]\n```\n\n### serialization\n\njson Marshal and Umarshal supported. \n\nIf Nil, the encoded json data is `null`.\n\n\n\n\n# License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleavez%2Fgo-optional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleavez%2Fgo-optional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleavez%2Fgo-optional/lists"}