{"id":26720935,"url":"https://github.com/cospectrum/option","last_synced_at":"2025-10-06T20:05:31.586Z","repository":{"id":251777532,"uuid":"838382853","full_name":"cospectrum/option","owner":"cospectrum","description":"Option type for golang","archived":false,"fork":false,"pushed_at":"2024-08-05T20:34:01.000Z","size":20,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-21T14:02:33.018Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cospectrum.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-08-05T14:25:37.000Z","updated_at":"2025-07-05T12:19:38.000Z","dependencies_parsed_at":"2024-08-05T18:30:32.331Z","dependency_job_id":"a8206fd8-db57-4644-8cb7-22f7b7e0efd8","html_url":"https://github.com/cospectrum/option","commit_stats":null,"previous_names":["cospectrum/option"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/cospectrum/option","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cospectrum%2Foption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cospectrum%2Foption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cospectrum%2Foption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cospectrum%2Foption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cospectrum","download_url":"https://codeload.github.com/cospectrum/option/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cospectrum%2Foption/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278671745,"owners_count":26025745,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"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":"2025-03-27T19:35:06.084Z","updated_at":"2025-10-06T20:05:31.560Z","avatar_url":"https://github.com/cospectrum.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# option\n\n[![github]](https://github.com/cospectrum/option)\n[![goref]](https://pkg.go.dev/github.com/cospectrum/option)\n\n[github]: https://img.shields.io/badge/github-cospectrum/option-8da0cb?logo=github\n[goref]: https://pkg.go.dev/badge/github.com/cospectrum/option\n\nOption type for golang\n\n## Install\n```sh\ngo get -u github.com/cospectrum/option\n```\nRequires Go version `1.22.0` or greater.\n\n## Usage\n```go\nimport (\n\t\"fmt\"\n\n\t\"github.com/cospectrum/option\"\n)\n\nfunc main()\n\tdivide := func(numerator, denominator float64) option.Option[float64] {\n\t\tif denominator == 0.0 {\n\t\t\treturn option.None[float64]()\n\t\t}\n\t\treturn option.Some(numerator / denominator)\n\t}\n\n\t// The return value of the function is an option\n\tresult := divide(2.0, 3.0)\n\n\t// Pattern match to retrieve the value\n\tresult.Match(\n\t\tfunc(val float64) {\n\t\t\tfmt.Printf(\"Result: %v\\n\", val)\n\t\t},\n\t\tfunc() {\n\t\t\tfmt.Println(\"Cannot divide by 0\")\n\t\t},\n\t)\n}\n```\n\n### JSON\n```go\ntype U struct {\n\tNum option.Option[int] `json:\"num\"`\n}\n\nvar u U\njson.Unmarshal([]byte(`{\"num\": null}`), \u0026u) // =\u003e U{Num: option.None()}\njson.Unmarshal([]byte(`{}`), \u0026u) // =\u003e U{Num: option.None()}\njson.Unmarshal([]byte(`{\"num\": 0}`), \u0026u) // =\u003e U{Num: option.Some(0)}\njson.Unmarshal([]byte(`{\"num\": 3}`), \u0026u) // =\u003e U{Num: option.Some(3)}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcospectrum%2Foption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcospectrum%2Foption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcospectrum%2Foption/lists"}