{"id":21064173,"url":"https://github.com/moveaxlab/go-optional","last_synced_at":"2025-10-05T16:45:38.064Z","repository":{"id":222830028,"uuid":"758464191","full_name":"moveaxlab/go-optional","owner":"moveaxlab","description":"Our Optional generic implementation for Go. Sometimes we miss Java.","archived":false,"fork":false,"pushed_at":"2024-02-19T09:15:21.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-01T20:45:14.761Z","etag":null,"topics":["go","optional","repository"],"latest_commit_sha":null,"homepage":"","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/moveaxlab.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-02-16T11:30:27.000Z","updated_at":"2024-02-19T11:07:46.000Z","dependencies_parsed_at":"2024-02-16T13:46:41.746Z","dependency_job_id":"58c86237-5389-412a-b8d3-569ca3ca8834","html_url":"https://github.com/moveaxlab/go-optional","commit_stats":null,"previous_names":["moveaxlab/go-optional"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/moveaxlab/go-optional","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgo-optional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgo-optional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgo-optional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgo-optional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moveaxlab","download_url":"https://codeload.github.com/moveaxlab/go-optional/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgo-optional/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278486267,"owners_count":25994941,"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-05T02:00:06.059Z","response_time":54,"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":["go","optional","repository"],"created_at":"2024-11-19T17:48:41.887Z","updated_at":"2025-10-05T16:45:38.049Z","avatar_url":"https://github.com/moveaxlab.png","language":"Go","readme":"# Optionals in Go\n\nThis is a no nonsense zero dependency generic `Optional\u003cT\u003e` implementation for Go.\n\n## Installation\n\n```bash\ngo get github.com/moveaxlab/go-optional\n```\n\n## Usage\n\nReturn optionals from your repositories:\n\n```go\npackage repository\n\nimport (\n  \"context\"\n\n  \"github.com/moveaxlab/go-optional\"\n)\n\ntype Repository interface {\n  FindById(ctx context.Context, id string) optional.Optional[Entity]\n}\n\ntype repository struct {}\n\nfunc (r *repository) FindById(ctx context.Context, id string) optional.Optional[Entity] {\n  var entity Entity\n  var entityWasFound bool\n\n  // retrieve the entity in some way\n\n  if !entityWasFound {\n    return optional.Empty[Entity]()\n  }\n\n  return optional.Of(\u0026entity)\n}\n```\n\nThe use the optionals in your application logic:\n\n```go\npackage service\n\nfunc (s *service) DoSomeStuff(ctx context.Context) {\n  maybeEntity := s.repository.FindById(ctx, \"1\")\n\n  if maybeEntity.IsPresent() {\n    // we have the entity!\n    entity := maybeEntity.Get()\n  }\n}\n```\n\nThe `Optional` type offers these methods:\n\n- `IsPresent` returns true if there is a value in the optional\n- `Get` returns the value contained in the optional, and panics if it's empty\n- `OrElseGet` accepts a function in input, and returns the value contained\n  in the optional if present, or the result of the function otherwise\n- `OrElsePanic` returns the value contained in the optional if present,\n  or panics with a custom error passed in input\n- `IfPresent` runs the function passed as argument if the value is present,\n  passing it the value contained in the optional\n- `IfPresentOrElse` behaves like `IfPresent` for the first argument,\n  but calls the function passed as second argument if the optional is empty\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoveaxlab%2Fgo-optional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoveaxlab%2Fgo-optional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoveaxlab%2Fgo-optional/lists"}